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.

242 lines
7.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
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. static Texture2D texLogoCW = { 0 }; // Cinamon Works texture
  45. //----------------------------------------------------------------------------------
  46. // Logo Screen Functions Definition
  47. //----------------------------------------------------------------------------------
  48. // Logo Screen Initialization logic
  49. void InitLogoScreen(void)
  50. {
  51. // Initialize LOGO screen variables here!
  52. finishScreen = 0;
  53. framesCounter = 0;
  54. lettersCount = 0;
  55. logoPositionX = GetScreenWidth()/2 - 128;
  56. logoPositionY = GetScreenHeight()/2 - 128;
  57. topSideRecWidth = LOGO_RECS_SIDE;
  58. leftSideRecHeight = LOGO_RECS_SIDE;
  59. bottomSideRecWidth = LOGO_RECS_SIDE;
  60. rightSideRecHeight = LOGO_RECS_SIDE;
  61. for (int i = 0; i < 8; i++) raylib[i] = '\0';
  62. state = 0;
  63. alpha = 1.0f;
  64. texLogoCW = LoadTexture("resources/textures/cw_logo.png");
  65. }
  66. // Logo Screen Update logic
  67. void UpdateLogoScreen(void)
  68. {
  69. // Update LOGO screen variables here!
  70. if (state == 0) // State 0: Small box blinking
  71. {
  72. framesCounter++;
  73. if (framesCounter == 80)
  74. {
  75. state = 1;
  76. framesCounter = 0; // Reset counter... will be used later...
  77. }
  78. }
  79. else if (state == 1) // State 1: Top and left bars growing
  80. {
  81. topSideRecWidth += 8;
  82. leftSideRecHeight += 8;
  83. if (topSideRecWidth == 256) state = 2;
  84. }
  85. else if (state == 2) // State 2: Bottom and right bars growing
  86. {
  87. bottomSideRecWidth += 8;
  88. rightSideRecHeight += 8;
  89. if (bottomSideRecWidth == 256) state = 3;
  90. }
  91. else if (state == 3) // State 3: Letters appearing (one by one)
  92. {
  93. framesCounter++;
  94. if (framesCounter/10) // Every 12 frames, one more letter!
  95. {
  96. lettersCount++;
  97. framesCounter = 0;
  98. }
  99. switch (lettersCount)
  100. {
  101. case 1: raylib[0] = 'r'; break;
  102. case 2: raylib[1] = 'a'; break;
  103. case 3: raylib[2] = 'y'; break;
  104. case 4: raylib[3] = 'l'; break;
  105. case 5: raylib[4] = 'i'; break;
  106. case 6: raylib[5] = 'b'; break;
  107. default: break;
  108. }
  109. // When all letters have appeared...
  110. if (lettersCount >= 10)
  111. {
  112. state = 4;
  113. framesCounter = 0;
  114. }
  115. }
  116. else if (state == 4)
  117. {
  118. framesCounter++;
  119. if (framesCounter > 100)
  120. {
  121. alpha -= 0.02f;
  122. if (alpha <= 0.0f)
  123. {
  124. alpha = 0.0f;
  125. framesCounter = 0;
  126. state = 5;
  127. }
  128. }
  129. }
  130. else if (state == 5)
  131. {
  132. alpha += 0.02f;
  133. if (alpha >= 1.0f) alpha = 1.0f;
  134. framesCounter++;
  135. if (framesCounter > 200)
  136. {
  137. framesCounter = 0;
  138. state = 6;
  139. }
  140. }
  141. else if (state == 6)
  142. {
  143. alpha -= 0.02f;
  144. if (alpha >= 1.0f) alpha = 1.0f;
  145. framesCounter++;
  146. if (framesCounter > 100)
  147. {
  148. framesCounter = 0;
  149. finishScreen = 1;
  150. }
  151. }
  152. }
  153. // Logo Screen Draw logic
  154. void DrawLogoScreen(void)
  155. {
  156. if (state == 0)
  157. {
  158. if ((framesCounter/10)%2) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK);
  159. }
  160. else if (state == 1)
  161. {
  162. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
  163. DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
  164. }
  165. else if (state == 2)
  166. {
  167. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
  168. DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
  169. DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK);
  170. DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK);
  171. }
  172. else if (state == 3)
  173. {
  174. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha));
  175. DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha));
  176. DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
  177. DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
  178. DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
  179. DrawText(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48, 50, Fade(BLACK, alpha));
  180. }
  181. else if (state == 4)
  182. {
  183. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha));
  184. DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha));
  185. DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
  186. DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
  187. DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
  188. DrawText(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48, 50, Fade(BLACK, alpha));
  189. if (framesCounter > 20) DrawText("powered by", logoPositionX, logoPositionY - 27, 20, Fade(DARKGRAY, alpha));
  190. }
  191. else if ((state == 5) || (state == 6)) DrawTexture(texLogoCW, GetScreenWidth()/2 - texLogoCW.width/2, GetScreenHeight()/2 - texLogoCW.height/2, Fade(WHITE, alpha));
  192. }
  193. // Logo Screen Unload logic
  194. void UnloadLogoScreen(void)
  195. {
  196. // Unload LOGO screen variables here!
  197. UnloadTexture(texLogoCW);
  198. }
  199. // Logo Screen should finish?
  200. int FinishLogoScreen(void)
  201. {
  202. return finishScreen;
  203. }