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.

156 lines
5.3 KiB

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