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.

184 lines
5.8 KiB

  1. /**********************************************************************************************
  2. *
  3. * raylib - Standard Game template
  4. *
  5. * Level05 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. #define NUM_CIRCLES 10
  28. //----------------------------------------------------------------------------------
  29. // Global Variables Definition (local to this module)
  30. //----------------------------------------------------------------------------------
  31. // Level05 screen global variables
  32. static int framesCounter;
  33. static int finishScreen;
  34. static Vector2 circleCenter;
  35. static float circleRadius[NUM_CIRCLES];
  36. static bool circleLocked[NUM_CIRCLES];
  37. static Color circleColor[NUM_CIRCLES];
  38. static bool done = false;
  39. static int levelTimeSec = 0;
  40. static bool levelFinished = false;
  41. //----------------------------------------------------------------------------------
  42. // Level05 Screen Functions Definition
  43. //----------------------------------------------------------------------------------
  44. static bool CheckColor(Color col1, Color col2);
  45. // Level05 Screen Initialization logic
  46. void InitLevel05Screen(void)
  47. {
  48. // Initialize Level05 screen variables here!
  49. framesCounter = 0;
  50. finishScreen = 0;
  51. circleCenter = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 };
  52. for (int i = 0; i < NUM_CIRCLES; i++)
  53. {
  54. circleRadius[i] = 760/NUM_CIRCLES*(NUM_CIRCLES - i);
  55. circleLocked[i] = false;
  56. }
  57. // That's a dirty hack to give sonme coherence to this puzzle...
  58. circleColor[9] = GRAY;
  59. circleColor[8] = RAYWHITE;
  60. circleColor[7] = RAYWHITE;
  61. circleColor[6] = GRAY;
  62. circleColor[5] = RAYWHITE;
  63. circleColor[4] = GRAY;
  64. circleColor[3] = GRAY;
  65. circleColor[2] = GRAY;
  66. circleColor[1] = RAYWHITE;
  67. circleColor[0] = GRAY;
  68. }
  69. // Level05 Screen Update logic
  70. void UpdateLevel05Screen(void)
  71. {
  72. // Update Level05 screen variables here!
  73. framesCounter++;
  74. if (!done)
  75. {
  76. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  77. {
  78. for (int i = NUM_CIRCLES - 1; i >= 0; i--)
  79. {
  80. if (CheckCollisionPointCircle(GetMousePosition(), circleCenter, circleRadius[i]))
  81. {
  82. if (i == 0)
  83. {
  84. if (CheckColor(circleColor[8], GRAY)) circleColor[8] = RAYWHITE;
  85. else circleColor[8] = GRAY;
  86. }
  87. else if (i == 2)
  88. {
  89. if (CheckColor(circleColor[5], GRAY)) circleColor[5] = RAYWHITE;
  90. else circleColor[5] = GRAY;
  91. }
  92. else if (i == 3)
  93. {
  94. if (CheckColor(circleColor[6], GRAY)) circleColor[6] = RAYWHITE;
  95. else circleColor[6] = GRAY;
  96. }
  97. else
  98. {
  99. if (CheckColor(circleColor[i], GRAY)) circleColor[i] = RAYWHITE;
  100. else circleColor[i] = GRAY;
  101. }
  102. return;
  103. }
  104. }
  105. }
  106. // Check all cicles done
  107. for (int i = 0; i < NUM_CIRCLES; i++)
  108. {
  109. done = true;
  110. if (CheckColor(circleColor[i], RAYWHITE))
  111. {
  112. done = false;
  113. return;
  114. }
  115. //if (done) PlaySound(levelWin);
  116. }
  117. }
  118. if (done && !levelFinished)
  119. {
  120. levelTimeSec = framesCounter/60;
  121. levelFinished = true;
  122. framesCounter = 0;
  123. }
  124. if (levelFinished)
  125. {
  126. framesCounter++;
  127. if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true;
  128. }
  129. }
  130. // Level05 Screen Draw logic
  131. void DrawLevel05Screen(void)
  132. {
  133. // Draw Level05 screen
  134. for (int i = 0; i < NUM_CIRCLES; i++)
  135. {
  136. DrawPoly(circleCenter, 64, circleRadius[i], 0.0f, circleColor[i]);
  137. }
  138. if (levelFinished)
  139. {
  140. DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f));
  141. DrawText("LEVEL 05", GetScreenWidth()/2 - MeasureText("LEVEL 05", 30)/2, 20, 30, GRAY);
  142. DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY);
  143. }
  144. else DrawText("LEVEL 05", GetScreenWidth()/2 - MeasureText("LEVEL 05", 30)/2, 20, 30, LIGHTGRAY);
  145. }
  146. // Level05 Screen Unload logic
  147. void UnloadLevel05Screen(void)
  148. {
  149. // TODO: Unload Level05 screen variables here!
  150. }
  151. // Level05 Screen should finish?
  152. int FinishLevel05Screen(void)
  153. {
  154. return finishScreen;
  155. }
  156. static bool CheckColor(Color col1, Color col2)
  157. {
  158. return ((col1.r == col2.r) && (col1.g == col2.g) && (col1.b == col2.b) && (col1.a == col2.a));
  159. }