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.

180 lines
5.8 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;
  33. static int finishScreen;
  34. static int logoPositionX;
  35. static int logoPositionY;
  36. static int lettersCount;
  37. static int topSideRecWidth;
  38. static int leftSideRecHeight;
  39. static int bottomSideRecWidth;
  40. static int rightSideRecHeight;
  41. static int state; // 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. topSideRecWidth = LOGO_RECS_SIDE;
  56. leftSideRecHeight = LOGO_RECS_SIDE;
  57. bottomSideRecWidth = LOGO_RECS_SIDE;
  58. rightSideRecHeight = LOGO_RECS_SIDE;
  59. state = 0;
  60. alpha = 1.0f;
  61. }
  62. // Logo Screen Update logic
  63. void UpdateLogoScreen(void)
  64. {
  65. // Update LOGO screen variables here!
  66. if (state == 0) // State 0: Small box blinking
  67. {
  68. framesCounter++;
  69. if (framesCounter == 80)
  70. {
  71. state = 1;
  72. framesCounter = 0; // Reset counter... will be used later...
  73. PlayMusicStream(music); // Start playing music... ;)
  74. }
  75. }
  76. else if (state == 1) // State 1: Top and left bars growing
  77. {
  78. topSideRecWidth += 8;
  79. leftSideRecHeight += 8;
  80. if (topSideRecWidth == 256) state = 2;
  81. }
  82. else if (state == 2) // State 2: Bottom and right bars growing
  83. {
  84. bottomSideRecWidth += 8;
  85. rightSideRecHeight += 8;
  86. if (bottomSideRecWidth == 256) state = 3;
  87. }
  88. else if (state == 3) // State 3: Letters appearing (one by one)
  89. {
  90. framesCounter++;
  91. if (lettersCount < 10)
  92. {
  93. if (framesCounter/15) // Every 12 frames, one more letter!
  94. {
  95. lettersCount++;
  96. framesCounter = 0;
  97. }
  98. }
  99. else // When all letters have appeared, just fade out everything
  100. {
  101. if (framesCounter > 200)
  102. {
  103. alpha -= 0.02f;
  104. if (alpha <= 0.0f)
  105. {
  106. alpha = 0.0f;
  107. finishScreen = 1;
  108. }
  109. }
  110. }
  111. }
  112. }
  113. // Logo Screen Draw logic
  114. void DrawLogoScreen(void)
  115. {
  116. if (state == 0)
  117. {
  118. if ((framesCounter/10)%2) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK);
  119. }
  120. else if (state == 1)
  121. {
  122. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
  123. DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
  124. }
  125. else if (state == 2)
  126. {
  127. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
  128. DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
  129. DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK);
  130. DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK);
  131. }
  132. else if (state == 3)
  133. {
  134. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha));
  135. DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha));
  136. DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
  137. DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
  138. DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
  139. DrawText(SubText("raylib", 0, lettersCount), GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48, 50, Fade(BLACK, alpha));
  140. if (framesCounter > 20) DrawText("powered by", logoPositionX, logoPositionY - 27, 20, Fade(DARKGRAY, alpha));
  141. }
  142. }
  143. // Logo Screen Unload logic
  144. void UnloadLogoScreen(void)
  145. {
  146. // Unload LOGO screen variables here!
  147. }
  148. // Logo Screen should finish?
  149. int FinishLogoScreen(void)
  150. {
  151. return finishScreen;
  152. }