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.

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