Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

204 righe
6.7 KiB

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