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.

177 lines
6.7 KiB

  1. /**********************************************************************************************
  2. *
  3. * raylib - Standard Game template
  4. *
  5. * Level07 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. // Level07 screen global variables
  31. static int framesCounter;
  32. static int finishScreen;
  33. static Vector2 leftCirclePos, middleCirclePos, rightCirclePos;
  34. static Vector2 leftBtnPos, middleBtnPos, rightBtnPos;
  35. static float circleRadius = 100;
  36. static float btnRadius = 80;
  37. static bool leftCircleActive, middleCircleActive, rightCircleActive;
  38. static Color leftCircleColor, middleCircleColor, rightCircleColor;
  39. static bool done = false;
  40. static int levelTimeSec = 0;
  41. static bool levelFinished = false;
  42. //----------------------------------------------------------------------------------
  43. // Level07 Screen Functions Definition
  44. //----------------------------------------------------------------------------------
  45. static bool CheckColor(Color col1, Color col2);
  46. // Level07 Screen Initialization logic
  47. void InitLevel07Screen(void)
  48. {
  49. // Initialize Level07 screen variables here!
  50. framesCounter = 0;
  51. finishScreen = 0;
  52. leftCirclePos = (Vector2){ GetScreenWidth()/2 - 340, GetScreenHeight()/2 - 100 };
  53. middleCirclePos = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 - 100 };
  54. rightCirclePos = (Vector2){ GetScreenWidth()/2 + 340, GetScreenHeight()/2 - 100 };
  55. leftBtnPos = (Vector2){ GetScreenWidth()/2 - 340, GetScreenHeight()/2 + 120 };
  56. middleBtnPos = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 + 120 };
  57. rightBtnPos = (Vector2){ GetScreenWidth()/2 + 340, GetScreenHeight()/2 + 120 };
  58. leftCircleActive = false;
  59. middleCircleActive = true;
  60. rightCircleActive = false;
  61. leftCircleColor = GRAY;
  62. middleCircleColor = GRAY;
  63. rightCircleColor = GRAY;
  64. }
  65. // Level07 Screen Update logic
  66. void UpdateLevel07Screen(void)
  67. {
  68. // Update Level07 screen variables here!
  69. framesCounter++;
  70. if (!done)
  71. {
  72. if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
  73. {
  74. if (CheckCollisionPointCircle(GetMousePosition(), leftBtnPos, btnRadius)) leftCircleActive = !leftCircleActive;
  75. else if (CheckCollisionPointCircle(GetMousePosition(), middleBtnPos, btnRadius)) middleCircleActive = !middleCircleActive;
  76. else if (CheckCollisionPointCircle(GetMousePosition(), rightBtnPos, btnRadius)) rightCircleActive = !rightCircleActive;
  77. if (rightCircleActive && CheckCollisionPointCircle(GetMousePosition(), leftCirclePos, circleRadius))
  78. {
  79. if (CheckColor(leftCircleColor, GRAY)) leftCircleColor = LIGHTGRAY;
  80. else leftCircleColor = GRAY;
  81. }
  82. if (middleCircleActive && CheckCollisionPointCircle(GetMousePosition(), middleCirclePos, circleRadius))
  83. {
  84. if (CheckColor(middleCircleColor, GRAY)) middleCircleColor = LIGHTGRAY;
  85. else middleCircleColor = GRAY;
  86. }
  87. if (rightCircleActive && leftCircleActive && CheckCollisionPointCircle(GetMousePosition(), rightCirclePos, circleRadius))
  88. {
  89. if (CheckColor(rightCircleColor, GRAY)) rightCircleColor = LIGHTGRAY;
  90. else rightCircleColor = GRAY;
  91. }
  92. }
  93. // Check all cicles done
  94. if (CheckColor(leftCircleColor, LIGHTGRAY) && CheckColor(middleCircleColor, LIGHTGRAY) && CheckColor(rightCircleColor, LIGHTGRAY) &&
  95. !leftCircleActive && !middleCircleActive && !rightCircleActive)
  96. {
  97. done = true;
  98. PlaySound(levelWin);
  99. }
  100. }
  101. if (done && !levelFinished)
  102. {
  103. levelTimeSec = framesCounter/60;
  104. levelFinished = true;
  105. framesCounter = 0;
  106. }
  107. if (levelFinished)
  108. {
  109. framesCounter++;
  110. if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true;
  111. }
  112. }
  113. // Level07 Screen Draw logic
  114. void DrawLevel07Screen(void)
  115. {
  116. // Draw Level07 screen here!
  117. DrawCircleV(leftCirclePos, circleRadius, leftCircleColor);
  118. DrawCircleV(middleCirclePos, circleRadius, middleCircleColor);
  119. DrawCircleV(rightCirclePos, circleRadius, rightCircleColor);
  120. if (leftCircleActive) DrawCircleV(leftBtnPos, btnRadius, GRAY);
  121. else DrawCircleV(leftBtnPos, btnRadius, LIGHTGRAY);
  122. if (middleCircleActive) DrawCircleV(middleBtnPos, btnRadius, GRAY);
  123. else DrawCircleV(middleBtnPos, btnRadius, LIGHTGRAY);
  124. if (rightCircleActive) DrawCircleV(rightBtnPos, btnRadius, GRAY);
  125. else DrawCircleV(rightBtnPos, btnRadius, LIGHTGRAY);
  126. if (levelFinished)
  127. {
  128. DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f));
  129. DrawText("LEVEL 07", GetScreenWidth()/2 - MeasureText("LEVEL 07", 30)/2, 20, 30, GRAY);
  130. DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY);
  131. }
  132. else DrawText("LEVEL 07", GetScreenWidth()/2 - MeasureText("LEVEL 07", 30)/2, 20, 30, LIGHTGRAY);
  133. }
  134. // Level07 Screen Unload logic
  135. void UnloadLevel07Screen(void)
  136. {
  137. // TODO: Unload Level07 screen variables here!
  138. }
  139. // Level07 Screen should finish?
  140. int FinishLevel07Screen(void)
  141. {
  142. return finishScreen;
  143. }
  144. static bool CheckColor(Color col1, Color col2)
  145. {
  146. return ((col1.r == col2.r) && (col1.g == col2.g) && (col1.b == col2.b) && (col1.a == col2.a));
  147. }