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.

146 lines
4.7 KiB

  1. /**********************************************************************************************
  2. *
  3. * raylib - Standard Game template
  4. *
  5. * Level04 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. // Level04 screen global variables
  31. static int framesCounter;
  32. static int finishScreen;
  33. static Vector2 circlesCenter;
  34. static float innerCircleRadius = 40;
  35. static float outerCircleRadius = 300;
  36. static bool done = false;
  37. static int levelTimeSec = 0;
  38. static bool levelFinished = false;
  39. //----------------------------------------------------------------------------------
  40. // Level04 Screen Functions Definition
  41. //----------------------------------------------------------------------------------
  42. // Level04 Screen Initialization logic
  43. void InitLevel04Screen(void)
  44. {
  45. // Initialize Level04 screen variables here!
  46. framesCounter = 0;
  47. finishScreen = 0;
  48. circlesCenter = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 };
  49. }
  50. // Level04 Screen Update logic
  51. void UpdateLevel04Screen(void)
  52. {
  53. // Update Level04 screen variables here!
  54. framesCounter++;
  55. if (!done)
  56. {
  57. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  58. {
  59. if (CheckCollisionPointCircle(GetMousePosition(), circlesCenter, innerCircleRadius))
  60. {
  61. innerCircleRadius += 2;
  62. }
  63. else if (CheckCollisionPointCircle(GetMousePosition(), circlesCenter, outerCircleRadius))
  64. {
  65. outerCircleRadius += 2;
  66. }
  67. else
  68. {
  69. outerCircleRadius -= 2;
  70. if (outerCircleRadius <= 260) outerCircleRadius = 260;
  71. }
  72. }
  73. else
  74. {
  75. if (!done)
  76. {
  77. innerCircleRadius -= 2;
  78. if (outerCircleRadius > 300) outerCircleRadius -= 2;
  79. }
  80. }
  81. if (innerCircleRadius >= 270) innerCircleRadius = 270;
  82. else if (innerCircleRadius <= 40) innerCircleRadius = 40;
  83. if (outerCircleRadius >= 600) outerCircleRadius = 600;
  84. if (innerCircleRadius >= outerCircleRadius)
  85. {
  86. done = true;
  87. PlaySound(levelWin);
  88. }
  89. }
  90. if (done && !levelFinished)
  91. {
  92. levelTimeSec = framesCounter/60;
  93. levelFinished = true;
  94. framesCounter = 0;
  95. }
  96. if (levelFinished)
  97. {
  98. framesCounter++;
  99. if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true;
  100. }
  101. }
  102. // Level04 Screen Draw logic
  103. void DrawLevel04Screen(void)
  104. {
  105. // Draw Level04 screen here!
  106. //DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), GRAY);
  107. DrawCircleV(circlesCenter, outerCircleRadius, GRAY);
  108. DrawCircleV(circlesCenter, innerCircleRadius, RAYWHITE);
  109. if (levelFinished)
  110. {
  111. DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f));
  112. DrawText("LEVEL 04", GetScreenWidth()/2 - MeasureText("LEVEL 04", 30)/2, 20, 30, GRAY);
  113. DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY);
  114. }
  115. else DrawText("LEVEL 04", GetScreenWidth()/2 - MeasureText("LEVEL 04", 30)/2, 20, 30, LIGHTGRAY);
  116. }
  117. // Level04 Screen Unload logic
  118. void UnloadLevel04Screen(void)
  119. {
  120. // TODO: Unload Level04 screen variables here!
  121. }
  122. // Level04 Screen should finish?
  123. int FinishLevel04Screen(void)
  124. {
  125. return finishScreen;
  126. }