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.

159 lines
5.6 KiB

преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 9 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 11 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 11 години
преди 10 години
преди 10 години
  1. /*******************************************************************************************
  2. *
  3. * raylib [shapes] example - raylib logo animation
  4. *
  5. * This example has been created using raylib 1.4 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2014 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main()
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. int screenWidth = 800;
  17. int screenHeight = 450;
  18. InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo animation");
  19. int logoPositionX = screenWidth/2 - 128;
  20. int logoPositionY = screenHeight/2 - 128;
  21. int framesCounter = 0;
  22. int lettersCount = 0;
  23. int topSideRecWidth = 16;
  24. int leftSideRecHeight = 16;
  25. int bottomSideRecWidth = 16;
  26. int rightSideRecHeight = 16;
  27. int state = 0; // Tracking animation states (State Machine)
  28. float alpha = 1.0f; // Useful for fading
  29. SetTargetFPS(60);
  30. //--------------------------------------------------------------------------------------
  31. // Main game loop
  32. while (!WindowShouldClose()) // Detect window close button or ESC key
  33. {
  34. // Update
  35. //----------------------------------------------------------------------------------
  36. if (state == 0) // State 0: Small box blinking
  37. {
  38. framesCounter++;
  39. if (framesCounter == 120)
  40. {
  41. state = 1;
  42. framesCounter = 0; // Reset counter... will be used later...
  43. }
  44. }
  45. else if (state == 1) // State 1: Top and left bars growing
  46. {
  47. topSideRecWidth += 4;
  48. leftSideRecHeight += 4;
  49. if (topSideRecWidth == 256) state = 2;
  50. }
  51. else if (state == 2) // State 2: Bottom and right bars growing
  52. {
  53. bottomSideRecWidth += 4;
  54. rightSideRecHeight += 4;
  55. if (bottomSideRecWidth == 256) state = 3;
  56. }
  57. else if (state == 3) // State 3: Letters appearing (one by one)
  58. {
  59. framesCounter++;
  60. if (framesCounter/12) // Every 12 frames, one more letter!
  61. {
  62. lettersCount++;
  63. framesCounter = 0;
  64. }
  65. if (lettersCount >= 10) // When all letters have appeared, just fade out everything
  66. {
  67. alpha -= 0.02f;
  68. if (alpha <= 0.0f)
  69. {
  70. alpha = 0.0f;
  71. state = 4;
  72. }
  73. }
  74. }
  75. else if (state == 4) // State 4: Reset and Replay
  76. {
  77. if (IsKeyPressed('R'))
  78. {
  79. framesCounter = 0;
  80. lettersCount = 0;
  81. topSideRecWidth = 16;
  82. leftSideRecHeight = 16;
  83. bottomSideRecWidth = 16;
  84. rightSideRecHeight = 16;
  85. alpha = 1.0f;
  86. state = 0; // Return to State 0
  87. }
  88. }
  89. //----------------------------------------------------------------------------------
  90. // Draw
  91. //----------------------------------------------------------------------------------
  92. BeginDrawing();
  93. ClearBackground(RAYWHITE);
  94. if (state == 0)
  95. {
  96. if ((framesCounter/15)%2) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK);
  97. }
  98. else if (state == 1)
  99. {
  100. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
  101. DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
  102. }
  103. else if (state == 2)
  104. {
  105. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
  106. DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
  107. DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK);
  108. DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK);
  109. }
  110. else if (state == 3)
  111. {
  112. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha));
  113. DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha));
  114. DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
  115. DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
  116. DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
  117. DrawText(SubText("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
  118. }
  119. else if (state == 4)
  120. {
  121. DrawText("[R] REPLAY", 340, 200, 20, GRAY);
  122. }
  123. EndDrawing();
  124. //----------------------------------------------------------------------------------
  125. }
  126. // De-Initialization
  127. //--------------------------------------------------------------------------------------
  128. CloseWindow(); // Close window and OpenGL context
  129. //--------------------------------------------------------------------------------------
  130. return 0;
  131. }