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.

162 lines
5.7 KiB

  1. /**********************************************************************************************
  2. *
  3. * raylib - Standard Game template
  4. *
  5. * Level01 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. // Level01 screen global variables
  31. static int framesCounter;
  32. static int finishScreen;
  33. static Rectangle innerLeftRec, outerLeftRec;
  34. static Rectangle innerRightRec, outerRightRec;
  35. static bool done = false;
  36. static int levelTimeSec = 0;
  37. static bool levelFinished = false;
  38. //----------------------------------------------------------------------------------
  39. // Level01 Screen Functions Definition
  40. //----------------------------------------------------------------------------------
  41. // Level01 Screen Initialization logic
  42. void InitLevel01Screen(void)
  43. {
  44. // Initialize Level01 screen variables here!
  45. framesCounter = 0;
  46. finishScreen = 0;
  47. outerLeftRec = (Rectangle){ 0, 0, GetScreenWidth()/2, GetScreenHeight() };
  48. outerRightRec = (Rectangle){ GetScreenWidth()/2, 0, GetScreenWidth()/2, GetScreenHeight() };
  49. innerLeftRec = (Rectangle){ GetScreenWidth()/4 - 200, GetScreenHeight()/2 - 200, 400, 400};
  50. innerRightRec = (Rectangle){ GetScreenWidth()/2 + GetScreenWidth()/4 - 200, GetScreenHeight()/2 - 200, 400, 400};
  51. }
  52. // Level01 Screen Update logic
  53. void UpdateLevel01Screen(void)
  54. {
  55. // Update Level01 screen
  56. framesCounter++;
  57. if (!done)
  58. {
  59. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  60. {
  61. if (CheckCollisionPointRec(GetMousePosition(), innerLeftRec))
  62. {
  63. if (innerRightRec.width > 0)
  64. {
  65. innerRightRec.x += 20;
  66. innerRightRec.y += 20;
  67. innerRightRec.width -= 40;
  68. innerRightRec.height -= 40;
  69. }
  70. }
  71. else if (CheckCollisionPointRec(GetMousePosition(), innerRightRec))
  72. {
  73. if (innerLeftRec.width > 0)
  74. {
  75. innerLeftRec.x += 20;
  76. innerLeftRec.y += 20;
  77. innerLeftRec.width -= 40;
  78. innerLeftRec.height -= 40;
  79. }
  80. }
  81. else if (CheckCollisionPointRec(GetMousePosition(), outerLeftRec))
  82. {
  83. innerLeftRec.x -= 20;
  84. innerLeftRec.y -= 20;
  85. innerLeftRec.width += 40;
  86. innerLeftRec.height += 40;
  87. }
  88. else if (CheckCollisionPointRec(GetMousePosition(), outerRightRec))
  89. {
  90. innerRightRec.x -= 20;
  91. innerRightRec.y -= 20;
  92. innerRightRec.width += 40;
  93. innerRightRec.height += 40;
  94. }
  95. }
  96. if (((innerRightRec.width == 0) && (innerLeftRec.height >= GetScreenHeight())) ||
  97. ((innerLeftRec.width == 0) && (innerRightRec.height >= GetScreenHeight())))
  98. {
  99. done = true;
  100. PlaySound(levelWin);
  101. }
  102. }
  103. if (done && !levelFinished)
  104. {
  105. levelTimeSec = framesCounter/60;
  106. levelFinished = true;
  107. framesCounter = 0;
  108. }
  109. if (levelFinished)
  110. {
  111. framesCounter++;
  112. if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true;
  113. }
  114. }
  115. // Level01 Screen Draw logic
  116. void DrawLevel01Screen(void)
  117. {
  118. // Draw Level01 screen
  119. if (!levelFinished) DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), LIGHTGRAY);
  120. else DrawRectangle(60, 60, GetScreenWidth() - 120, GetScreenHeight() - 120, LIGHTGRAY);
  121. DrawRectangleRec(outerLeftRec, GRAY);
  122. DrawRectangleRec(innerLeftRec, RAYWHITE);
  123. DrawRectangleRec(outerRightRec, RAYWHITE);
  124. DrawRectangleRec(innerRightRec, GRAY);
  125. if (levelFinished)
  126. {
  127. DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f));
  128. DrawText("LEVEL 01", GetScreenWidth()/2 - MeasureText("LEVEL 01", 30)/2, 20, 30, GRAY);
  129. DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY);
  130. }
  131. else DrawText("LEVEL 01", GetScreenWidth()/2 - MeasureText("LEVEL 01", 30)/2, 20, 30, LIGHTGRAY);
  132. }
  133. // Level01 Screen Unload logic
  134. void UnloadLevel01Screen(void)
  135. {
  136. // TODO: Unload Level01 screen variables here!
  137. }
  138. // Level01 Screen should finish?
  139. int FinishLevel01Screen(void)
  140. {
  141. return finishScreen;
  142. }