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.

133 lines
4.4 KiB

  1. /**********************************************************************************************
  2. *
  3. * raylib - Standard Game template
  4. *
  5. * Level03 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. // Level03 screen global variables
  31. static int framesCounter;
  32. static int finishScreen;
  33. static Rectangle holeRec, pieceRec;
  34. static bool showPiece = false;
  35. static bool pieceSelected = false;
  36. static bool done = false;
  37. static int levelTimeSec = 0;
  38. static bool levelFinished = false;
  39. //----------------------------------------------------------------------------------
  40. // Level03 Screen Functions Definition
  41. //----------------------------------------------------------------------------------
  42. // Level03 Screen Initialization logic
  43. void InitLevel03Screen(void)
  44. {
  45. // Initialize Level03 screen variables here!
  46. framesCounter = 0;
  47. finishScreen = 0;
  48. holeRec = (Rectangle){ GetScreenWidth()/2 - 50, GetScreenHeight()/2 - 50, 100, 100 };
  49. pieceRec = (Rectangle){ 200, 400, 100, 100 };
  50. }
  51. // Level03 Screen Update logic
  52. void UpdateLevel03Screen(void)
  53. {
  54. // Update Level03 screen variables here!
  55. framesCounter++;
  56. Vector2 mousePos = GetMousePosition();
  57. if (!done)
  58. {
  59. if (CheckCollisionPointRec(mousePos, holeRec)) showPiece = true;
  60. else showPiece = false;
  61. if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
  62. {
  63. if (CheckCollisionPointRec(mousePos, pieceRec))
  64. {
  65. pieceSelected = true;
  66. pieceRec.x = ((int)mousePos.x - 50);
  67. pieceRec.y = ((int)mousePos.y - 50);
  68. }
  69. }
  70. if ((pieceRec.x == holeRec.x) && !(CheckCollisionPointRec(mousePos, holeRec)))
  71. {
  72. done = true;
  73. PlaySound(levelWin);
  74. }
  75. }
  76. if (done && !levelFinished)
  77. {
  78. levelTimeSec = framesCounter/60;
  79. levelFinished = true;
  80. framesCounter = 0;
  81. }
  82. if (levelFinished)
  83. {
  84. framesCounter++;
  85. if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true;
  86. }
  87. }
  88. // Level03 Screen Draw logic
  89. void DrawLevel03Screen(void)
  90. {
  91. // Draw Level03 screen
  92. DrawRectangleRec(holeRec, GRAY);
  93. DrawRectangleRec(pieceRec, RAYWHITE);
  94. if (showPiece) DrawRectangleLines(pieceRec.x, pieceRec.y, pieceRec.width, pieceRec.height, Fade(LIGHTGRAY, 0.8f));
  95. if (levelFinished)
  96. {
  97. DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f));
  98. DrawText("LEVEL 03", GetScreenWidth()/2 - MeasureText("LEVEL 03", 30)/2, 20, 30, GRAY);
  99. DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY);
  100. }
  101. else DrawText("LEVEL 03", GetScreenWidth()/2 - MeasureText("LEVEL 03", 30)/2, 20, 30, LIGHTGRAY);
  102. }
  103. // Level03 Screen Unload logic
  104. void UnloadLevel03Screen(void)
  105. {
  106. // TODO: Unload Level03 screen variables here!
  107. }
  108. // Level03 Screen should finish?
  109. int FinishLevel03Screen(void)
  110. {
  111. return finishScreen;
  112. }