shapes_logo_raylib_anim.bmx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. SuperStrict
  2. Framework Ray.Lib
  3. ' Initialization
  4. '--------------------------------------------------------------------------------------
  5. Const screenWidth:Int = 800
  6. Const screenHeight:Int = 450
  7. InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo animation")
  8. Local logoPositionX:Int = screenWidth/2 - 128
  9. Local logoPositionY:Int = screenHeight/2 - 128
  10. Local framesCounter:Int = 0
  11. Local lettersCount:Int = 0
  12. Local topSideRecWidth:Int = 16
  13. Local leftSideRecHeight:Int = 16
  14. Local bottomSideRecWidth:Int = 16
  15. Local rightSideRecHeight:Int = 16
  16. Local state:Int = 0 ' Tracking animation states (State Machine)
  17. Local alpha:Float = 1.0 ' Useful for fading
  18. SetTargetFPS(60) ' Set our game to run at 60 frames-per-second
  19. '--------------------------------------------------------------------------------------
  20. ' Main game loop
  21. While Not WindowShouldClose() ' Detect window close button or ESC key
  22. ' Update
  23. '----------------------------------------------------------------------------------
  24. If state = 0 Then ' State 0: Small box blinking
  25. framesCounter:+ 1
  26. If framesCounter = 120 Then
  27. state = 1
  28. framesCounter = 0 ' Reset counter... will be used later...
  29. End If
  30. Else If state = 1 Then ' State 1: Top and left bars growing
  31. topSideRecWidth :+ 4
  32. leftSideRecHeight :+ 4
  33. If topSideRecWidth = 256
  34. state = 2
  35. End If
  36. Else If state = 2 Then ' State 2: Bottom and right bars growing
  37. bottomSideRecWidth :+ 4
  38. rightSideRecHeight :+ 4
  39. If bottomSideRecWidth = 256 Then
  40. state = 3
  41. End If
  42. Else If state = 3 Then ' State 3: Letters appearing (one by one)
  43. framesCounter :+ 1
  44. If framesCounter/12 Then ' Every 12 frames, one more letter!
  45. lettersCount :+ 1
  46. framesCounter = 0
  47. End If
  48. If lettersCount >= 10 Then ' When all letters have appeared, just fade out everything
  49. alpha :- 0.02
  50. If alpha <= 0.0 Then
  51. alpha = 0.0
  52. state = 4
  53. End If
  54. End If
  55. Else If state = 4 ' State 4: Reset and Replay
  56. If IsKeyPressed(Asc("R"))
  57. framesCounter = 0
  58. lettersCount = 0
  59. topSideRecWidth = 16
  60. leftSideRecHeight = 16
  61. bottomSideRecWidth = 16
  62. rightSideRecHeight = 16
  63. alpha = 1.0
  64. state = 0 ' Return to State 0
  65. End If
  66. End If
  67. '----------------------------------------------------------------------------------
  68. ' Draw
  69. '----------------------------------------------------------------------------------
  70. BeginDrawing()
  71. ClearBackground(RAYWHITE)
  72. If state = 0 Then
  73. If (framesCounter / 15) Mod 2 Then
  74. DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK)
  75. End If
  76. Else If state = 1 Then
  77. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK)
  78. DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK)
  79. Else If state = 2 Then
  80. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK)
  81. DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK)
  82. DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK)
  83. DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK)
  84. Else If state = 3 Then
  85. DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha))
  86. DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha))
  87. DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha))
  88. DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha))
  89. DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha))
  90. DrawText("raylib"[..lettersCount], screenWidth/2 - 44, screenHeight/2 + 8, 50, Fade(BLACK, alpha))
  91. DrawText("blitzmax"[..lettersCount], screenWidth/2 - 94, screenHeight/2 + 48, 50, Fade(BLACK, alpha))
  92. Else If state = 4 Then
  93. DrawText("[R] REPLAY", 340, 200, 20, GRAY)
  94. End If
  95. EndDrawing()
  96. '----------------------------------------------------------------------------------
  97. Wend
  98. ' De-Initialization
  99. '--------------------------------------------------------------------------------------
  100. CloseWindow() ' Close window and OpenGL context
  101. '--------------------------------------------------------------------------------------