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.

226 lines
7.4 KiB

6 years ago
  1. /**********************************************************************************************
  2. *
  3. * raylib - Standard Game template
  4. *
  5. * Logo 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. #include <string.h>
  28. //----------------------------------------------------------------------------------
  29. // Global Variables Definition (local to this module)
  30. //----------------------------------------------------------------------------------
  31. // Logo screen global variables
  32. static int framesCounter;
  33. static int finishScreen;
  34. const char msgLogoA[64] = "A simple and easy-to-use library";
  35. const char msgLogoB[64] = "to enjoy videogames programming";
  36. int logoPositionX;
  37. int logoPositionY;
  38. int raylibLettersCount = 0;
  39. int topSideRecWidth = 16;
  40. int leftSideRecHeight = 16;
  41. int bottomSideRecWidth = 16;
  42. int rightSideRecHeight = 16;
  43. char raylib[8] = " \0"; // raylib text array, max 8 letters
  44. int logoScreenState = 0; // Tracking animation states (State Machine)
  45. bool msgLogoADone = false;
  46. bool msgLogoBDone = false;
  47. int lettersCounter = 0;
  48. char msgBuffer[128] = { ' ' };
  49. //----------------------------------------------------------------------------------
  50. // Logo Screen Functions Definition
  51. //----------------------------------------------------------------------------------
  52. // Logo Screen Initialization logic
  53. void InitLogoScreen(void)
  54. {
  55. // Initialize LOGO screen variables here!
  56. framesCounter = 0;
  57. finishScreen = 0;
  58. logoPositionX = GetScreenWidth()/2 - 128;
  59. logoPositionY = GetScreenHeight()/2 - 128;
  60. }
  61. // Logo Screen Update logic
  62. void UpdateLogoScreen(void)
  63. {
  64. // Update LOGO screen
  65. framesCounter++; // Count frames
  66. // Update LOGO screen variables
  67. if (logoScreenState == 0) // State 0: Small box blinking
  68. {
  69. framesCounter++;
  70. if (framesCounter == 120)
  71. {
  72. logoScreenState = 1;
  73. framesCounter = 0; // Reset counter... will be used later...
  74. }
  75. }
  76. else if (logoScreenState == 1) // State 1: Top and left bars growing
  77. {
  78. topSideRecWidth += 4;
  79. leftSideRecHeight += 4;
  80. if (topSideRecWidth == 256) logoScreenState = 2;
  81. }
  82. else if (logoScreenState == 2) // State 2: Bottom and right bars growing
  83. {
  84. bottomSideRecWidth += 4;
  85. rightSideRecHeight += 4;
  86. if (bottomSideRecWidth == 256)
  87. {
  88. lettersCounter = 0;
  89. for (int i = 0; i < strlen(msgBuffer); i++) msgBuffer[i] = ' ';
  90. logoScreenState = 3;
  91. }
  92. }
  93. else if (logoScreenState == 3) // State 3: Letters appearing (one by one)
  94. {
  95. framesCounter++;
  96. // Every 12 frames, one more letter!
  97. if ((framesCounter%12) == 0) raylibLettersCount++;
  98. switch (raylibLettersCount)
  99. {
  100. case 1: raylib[0] = 'r'; break;
  101. case 2: raylib[1] = 'a'; break;
  102. case 3: raylib[2] = 'y'; break;
  103. case 4: raylib[3] = 'l'; break;
  104. case 5: raylib[4] = 'i'; break;
  105. case 6: raylib[5] = 'b'; break;
  106. default: break;
  107. }
  108. if (raylibLettersCount >= 10)
  109. {
  110. // Write raylib description messages
  111. if ((framesCounter%2) == 0) lettersCounter++;
  112. if (!msgLogoADone)
  113. {
  114. if (lettersCounter <= strlen(msgLogoA)) strncpy(msgBuffer, msgLogoA, lettersCounter);
  115. else
  116. {
  117. for (int i = 0; i < strlen(msgBuffer); i++) msgBuffer[i] = ' ';
  118. lettersCounter = 0;
  119. msgLogoADone = true;
  120. }
  121. }
  122. else if (!msgLogoBDone)
  123. {
  124. if (lettersCounter <= strlen(msgLogoB)) strncpy(msgBuffer, msgLogoB, lettersCounter);
  125. else
  126. {
  127. msgLogoBDone = true;
  128. framesCounter = 0;
  129. PlaySound(levelWin);
  130. }
  131. }
  132. }
  133. }
  134. // Wait for 2 seconds (60 frames) before jumping to TITLE screen
  135. if (msgLogoBDone)
  136. {
  137. framesCounter++;
  138. if (framesCounter > 90) finishScreen = true;
  139. }
  140. }
  141. // Logo Screen Draw logic
  142. void DrawLogoScreen(void)
  143. {
  144. // Draw LOGO screen
  145. if (logoScreenState == 0)
  146. {
  147. if ((framesCounter/15)%2) DrawRectangle(logoPositionX, logoPositionY - 60, 16, 16, BLACK);
  148. }
  149. else if (logoScreenState == 1)
  150. {
  151. DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK);
  152. DrawRectangle(logoPositionX, logoPositionY - 60, 16, leftSideRecHeight, BLACK);
  153. }
  154. else if (logoScreenState == 2)
  155. {
  156. DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK);
  157. DrawRectangle(logoPositionX, logoPositionY - 60, 16, leftSideRecHeight, BLACK);
  158. DrawRectangle(logoPositionX + 240, logoPositionY - 60, 16, rightSideRecHeight, BLACK);
  159. DrawRectangle(logoPositionX, logoPositionY + 240 - 60, bottomSideRecWidth, 16, BLACK);
  160. }
  161. else if (logoScreenState == 3)
  162. {
  163. DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK);
  164. DrawRectangle(logoPositionX, logoPositionY + 16 - 60, 16, leftSideRecHeight - 32, BLACK);
  165. DrawRectangle(logoPositionX + 240, logoPositionY + 16 - 60, 16, rightSideRecHeight - 32, BLACK);
  166. DrawRectangle(logoPositionX, logoPositionY + 240 - 60, bottomSideRecWidth, 16, BLACK);
  167. DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112 - 60, 224, 224, RAYWHITE);
  168. DrawText(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48 - 60, 50, BLACK);
  169. if (!msgLogoADone) DrawText(msgBuffer, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 230, 30, GRAY);
  170. else
  171. {
  172. DrawText(msgLogoA, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 230, 30, GRAY);
  173. if (!msgLogoBDone) DrawText(msgBuffer, GetScreenWidth()/2 - MeasureText(msgLogoB, 30)/2, logoPositionY + 280, 30, GRAY);
  174. else
  175. {
  176. DrawText(msgLogoB, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 280, 30, GRAY);
  177. }
  178. }
  179. }
  180. }
  181. // Logo Screen Unload logic
  182. void UnloadLogoScreen(void)
  183. {
  184. // TODO: Unload LOGO screen variables here!
  185. }
  186. // Logo Screen should finish?
  187. int FinishLogoScreen(void)
  188. {
  189. return finishScreen;
  190. }