You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
6.1 KiB

  1. /**********************************************************************************************
  2. *
  3. * raylib - Standard Game template
  4. *
  5. * Level00 Screen Functions Definitions (Init, Update, Draw, Unload)
  6. *
  7. * Copyright (c) 2014 Ramon Santamaria (@raysan5)
  8. *
  9. * This software is provided "as-is", without any express or implied warranty. In no event
  10. * will the authors be held liable for any damages arising from the use of this software.
  11. *
  12. * Permission is granted to anyone to use this software for any purpose, including commercial
  13. * applications, and to alter it and redistribute it freely, subject to the following restrictions:
  14. *
  15. * 1. The origin of this software must not be misrepresented; you must not claim that you
  16. * wrote the original software. If you use this software in a product, an acknowledgment
  17. * in the product documentation would be appreciated but is not required.
  18. *
  19. * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
  20. * as being the original software.
  21. *
  22. * 3. This notice may not be removed or altered from any source distribution.
  23. *
  24. **********************************************************************************************/
  25. #include "raylib.h"
  26. #include "screens.h"
  27. //----------------------------------------------------------------------------------
  28. // Global Variables Definition (local to this module)
  29. //----------------------------------------------------------------------------------
  30. // Level00 screen global variables
  31. static int framesCounter;
  32. static int finishScreen;
  33. static Rectangle boundsU, boundsO;
  34. static bool mouseOverU = false;
  35. static bool mouseOverO = false;
  36. static bool placedU = false;
  37. static bool placedO = false;
  38. static bool done = false;
  39. static int levelTimeSec = 0;
  40. static bool levelFinished = false;
  41. //----------------------------------------------------------------------------------
  42. // Level00 Screen Functions Definition
  43. //----------------------------------------------------------------------------------
  44. // Level00 Screen Initialization logic
  45. void InitLevel00Screen(void)
  46. {
  47. // Initialize Level00 screen variables here!
  48. framesCounter = 0;
  49. finishScreen = 0;
  50. boundsU = (Rectangle){GetScreenWidth()/2 - 265, -200, MeasureText("U", 160) + 40, 160 };
  51. boundsO = (Rectangle){GetScreenWidth() - 370, -30, MeasureText("O", 160) + 40, 160 };
  52. }
  53. // Level00 Screen Update logic
  54. void UpdateLevel00Screen(void)
  55. {
  56. // Update Level00 screen variables here!
  57. if (!done) framesCounter++;
  58. if (!done)
  59. {
  60. if (!placedU) boundsU.y += 2;
  61. if (boundsU.y >= GetScreenHeight()) boundsU.y = -boundsU.height;
  62. Vector2 mousePos = GetMousePosition();
  63. if (CheckCollisionPointRec(mousePos, boundsU))
  64. {
  65. mouseOverU = true;
  66. if (!placedU && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  67. {
  68. if ((boundsU.y > GetScreenHeight()/2 - 110) && ((boundsU.y + boundsU.height) < (GetScreenHeight()/2 + 100)))
  69. {
  70. placedU = true;
  71. }
  72. }
  73. }
  74. else mouseOverU = false;
  75. if (CheckCollisionPointRec(mousePos, boundsO))
  76. {
  77. mouseOverO = true;
  78. if (!placedO && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) boundsO.y += 100;
  79. if (boundsO.y >= (GetScreenHeight()/2 - 130)) placedO = true;
  80. }
  81. else mouseOverO = false;
  82. if (placedO && placedU)
  83. {
  84. done = true;
  85. PlaySound(levelWin);
  86. }
  87. }
  88. if (done && !levelFinished)
  89. {
  90. levelTimeSec = framesCounter/60;
  91. levelFinished = true;
  92. framesCounter = 0;
  93. }
  94. if (levelFinished)
  95. {
  96. framesCounter++;
  97. if ((framesCounter > 30) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true;
  98. }
  99. }
  100. // Level00 Screen Draw logic
  101. void DrawLevel00Screen(void)
  102. {
  103. // Draw Level00 screen
  104. DrawText("U", boundsU.x, boundsU.y + 10, 160, GRAY);
  105. DrawText("J", GetScreenWidth()/2 - MeasureText("JUST DO", 160)/2, GetScreenHeight()/2 - 80, 160, GRAY);
  106. DrawText("ST D", GetScreenWidth()/2 - MeasureText("JUST DO", 160)/2 + 210, GetScreenHeight()/2 - 80, 160, GRAY);
  107. DrawText("O", boundsO.x, boundsO.y + 10, 160, GRAY);
  108. DrawText("by RAMON SANTAMARIA (@raysan5)", 370, GetScreenHeight()/2 + 100, 30, Fade(LIGHTGRAY, 0.4f));
  109. if (mouseOverU && !placedU) DrawRectangleLines(boundsU.x - 20, boundsU.y, boundsU.width, boundsU.height, Fade(LIGHTGRAY, 0.8f));
  110. //DrawRectangleBordersRec(boundsU, -20, 0, 20, Fade(RED, 0.3f));
  111. if (mouseOverO && !placedO) DrawRectangleLines(boundsO.x - 20, boundsO.y, boundsO.width, boundsO.height, Fade(LIGHTGRAY, 0.8f));
  112. //DrawRectangleBordersRec(boundsO, -20, 0, 20, Fade(RED, 0.3f));
  113. if (levelFinished)
  114. {
  115. DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f));
  116. DrawText("LEVEL 00", GetScreenWidth()/2 - MeasureText("LEVEL 00", 30)/2, 20, 30, GRAY);
  117. DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY);
  118. }
  119. else DrawText("LEVEL 00", GetScreenWidth()/2 - MeasureText("LEVEL 00", 30)/2, 20, 30, LIGHTGRAY);
  120. }
  121. // Level00 Screen Unload logic
  122. void UnloadLevel00Screen(void)
  123. {
  124. // TODO: Unload Level00 screen variables here!
  125. }
  126. // Level00 Screen should finish?
  127. int FinishLevel00Screen(void)
  128. {
  129. return finishScreen;
  130. }
  131. void DrawRectangleBordersRec(Rectangle rec, int offsetX, int offsetY, int borderSize, Color col)
  132. {
  133. DrawRectangle(rec.x + offsetX, rec.y + offsetY, rec.width, borderSize, col);
  134. DrawRectangle(rec.x + offsetX, rec.y + borderSize + offsetY, borderSize, rec.height - borderSize*2, col);
  135. DrawRectangle(rec.x + rec.width - borderSize + offsetX, rec.y + borderSize + offsetY, borderSize, rec.height - borderSize*2, col);
  136. DrawRectangle(rec.x + offsetX, rec.y + rec.height - borderSize + offsetY, rec.width, borderSize, col);
  137. }