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.

210 lines
6.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. /**********************************************************************************************
  2. *
  3. * raylib - Advance Game template
  4. *
  5. * Logo Screen Functions Definitions (Init, Update, Draw, Unload)
  6. *
  7. * Copyright (c) 2014-2019 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 LOGO_RECS_SIDE 16
  28. //----------------------------------------------------------------------------------
  29. // Global Variables Definition (local to this module)
  30. //----------------------------------------------------------------------------------
  31. // Logo screen global variables
  32. static int framesCounter = 0;
  33. static int finishScreen = 0;
  34. static int logoPositionX = 0;
  35. static int logoPositionY = 0;
  36. static int lettersCount = 0;
  37. static int topSideRecWidth = 0;
  38. static int leftSideRecHeight = 0;
  39. static int bottomSideRecWidth = 0;
  40. static int rightSideRecHeight = 0;
  41. static char raylib[8] = { 0 }; // raylib text array, max 8 letters
  42. static int state = 0; // Tracking animation states (State Machine)
  43. static float alpha = 1.0f; // Useful for fading
  44. //----------------------------------------------------------------------------------
  45. // Logo Screen Functions Definition
  46. //----------------------------------------------------------------------------------
  47. // Logo Screen Initialization logic
  48. void InitLogoScreen(void)
  49. {
  50. // Initialize LOGO screen variables here!
  51. finishScreen = 0;
  52. framesCounter = 0;
  53. lettersCount = 0;
  54. logoPositionX = GetScreenWidth()/2 - 128;
  55. logoPositionY = GetScreenHeight()/2 - 128;
  56. topSideRecWidth = LOGO_RECS_SIDE;
  57. leftSideRecHeight = LOGO_RECS_SIDE;
  58. bottomSideRecWidth = LOGO_RECS_SIDE;
  59. rightSideRecHeight = LOGO_RECS_SIDE;
  60. for (int i = 0; i < 8; i++) raylib[i] = '\0';
  61. state = 0;
  62. alpha = 1.0f;
  63. }
  64. // Logo Screen Update logic
  65. void UpdateLogoScreen(void)
  66. {
  67. // Update LOGO screen variables here!
  68. if (state == 0) // State 0: Small box blinking
  69. {
  70. framesCounter++;
  71. if (framesCounter == 80)
  72. {
  73. state = 1;
  74. framesCounter = 0; // Reset counter... will be used later...
  75. }
  76. }
  77. else if (state == 1) // State 1: Top and left bars growing
  78. {
  79. topSideRecWidth += 8;
  80. leftSideRecHeight += 8;
  81. if (topSideRecWidth == 256) state = 2;
  82. }
  83. else if (state == 2) // State 2: Bottom and right bars growing
  84. {
  85. bottomSideRecWidth += 8;
  86. rightSideRecHeight += 8;
  87. if (bottomSideRecWidth == 256) state = 3;
  88. }
  89. else if (state == 3) // State 3: Letters appearing (one by one)
  90. {
  91. framesCounter++;
  92. if (framesCounter/10) // Every 12 frames, one more letter!
  93. {
  94. lettersCount++;
  95. framesCounter = 0;
  96. }
  97. switch (lettersCount)
  98. {
  99. case 1: raylib[0] = 'r'; break;
  100. case 2: raylib[1] = 'a'; break;
  101. case 3: raylib[2] = 'y'; break;
  102. case 4: raylib[3] = 'l'; break;
  103. case 5: raylib[4] = 'i'; break;
  104. case 6: raylib[5] = 'b'; break;
  105. default: break;
  106. }
  107. // When all letters have appeared...
  108. if (lettersCount >= 10)
  109. {
  110. state = 4;
  111. framesCounter = 0;
  112. }
  113. }
  114. else if (state == 4)
  115. {
  116. framesCounter++;
  117. if (framesCounter > 100)
  118. {
  119. alpha -= 0.02f;
  120. if (alpha <= 0.0f)
  121. {
  122. alpha = 0.0f;
  123. finishScreen = 1;
  124. }
  125. }
  126. }
  127. }
  128. // Logo Screen Draw logic
  129. void DrawLogoScreen(void)
  130. {
  131. if (state == 0)
  132. {
  133. if ((framesCounter/10)%2) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK);
  134. }
  135. else if (state == 1)
  136. {
  137. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
  138. DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
  139. }
  140. else if (state == 2)
  141. {
  142. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
  143. DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
  144. DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK);
  145. DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK);
  146. }
  147. else if (state == 3)
  148. {
  149. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha));
  150. DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha));
  151. DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
  152. DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
  153. DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
  154. DrawText(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48, 50, Fade(BLACK, alpha));
  155. }
  156. else if (state == 4)
  157. {
  158. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha));
  159. DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha));
  160. DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
  161. DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
  162. DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
  163. DrawText(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48, 50, Fade(BLACK, alpha));
  164. if (framesCounter > 20) DrawText("powered by", logoPositionX, logoPositionY - 27, 20, Fade(DARKGRAY, alpha));
  165. }
  166. }
  167. // Logo Screen Unload logic
  168. void UnloadLogoScreen(void)
  169. {
  170. // Unload LOGO screen variables here!
  171. }
  172. // Logo Screen should finish?
  173. int FinishLogoScreen(void)
  174. {
  175. return finishScreen;
  176. }