shapes_easings_box_anim.bmx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 - easings box anim")
  8. ' Box variables to be animated with easings
  9. Local rec:RRectangle = New RRectangle(GetScreenWidth()/2, -100, 100, 100)
  10. Local Rotation:Float = 0.0
  11. Local alpha:Float = 1.0
  12. Local state:Int = 0
  13. Local framesCounter:Int = 0
  14. SetTargetFPS(60) ' Set our game to run at 60 frames-per-second
  15. '--------------------------------------------------------------------------------------
  16. ' Main game loop
  17. While Not WindowShouldClose() ' Detect window close button or ESC key
  18. ' Update
  19. '----------------------------------------------------------------------------------
  20. Select state
  21. Case 0 ' Move box down to center of screen
  22. framesCounter :+ 1
  23. ' NOTE: Remember that 3rd parameter of easing function refers to
  24. ' desired value variation, do not confuse it with expected final value!
  25. rec.y = EaseElasticOut(framesCounter, -100, GetScreenHeight()/2 + 100, 120)
  26. If framesCounter >= 120 Then
  27. framesCounter = 0
  28. state = 1
  29. End If
  30. Case 1 ' Scale box to an horizontal bar
  31. framesCounter :+ 1
  32. rec.height = EaseBounceOut(framesCounter, 100, -90, 120)
  33. rec.width = EaseBounceOut(framesCounter, 100, GetScreenWidth(), 120)
  34. If framesCounter >= 120 Then
  35. framesCounter = 0
  36. state = 2
  37. End If
  38. Case 2 ' Rotate horizontal bar rectangle
  39. framesCounter :+ 1
  40. Rotation = EaseQuadOut(framesCounter, 0.0, 270.0, 240)
  41. If framesCounter >= 240 Then
  42. framesCounter = 0
  43. state = 3
  44. End If
  45. Case 3 ' Increase bar size to fill all screen
  46. framesCounter :+ 1
  47. rec.height = EaseCircOut(framesCounter, 10, GetScreenWidth(), 120)
  48. If framesCounter >= 120 Then
  49. framesCounter = 0
  50. state = 4
  51. End If
  52. Case 4 ' Fade out animation
  53. framesCounter :+ 1
  54. alpha = EaseSineOut(framesCounter, 1.0, -1.0, 160)
  55. If framesCounter >= 160 Then
  56. framesCounter = 0
  57. state = 5
  58. End If
  59. End Select
  60. ' Reset animation at any moment
  61. If IsKeyPressed(KEY_SPACE) Then
  62. rec = New RRectangle(GetScreenWidth()/2, -100, 100, 100)
  63. Rotation = 0.0
  64. alpha = 1.0
  65. state = 0
  66. framesCounter = 0
  67. End If
  68. '----------------------------------------------------------------------------------
  69. ' Draw
  70. '----------------------------------------------------------------------------------
  71. BeginDrawing()
  72. ClearBackground(RAYWHITE)
  73. DrawRectanglePro(rec, New RVector2(rec.width/2, rec.height/2), Rotation, Fade(BLACK, alpha))
  74. DrawText("PRESS [SPACE] TO RESET BOX ANIMATION!", 10, GetScreenHeight() - 25, 20, LIGHTGRAY)
  75. EndDrawing()
  76. '----------------------------------------------------------------------------------
  77. Wend
  78. ' De-Initialization
  79. '--------------------------------------------------------------------------------------
  80. CloseWindow() ' Close window and OpenGL context
  81. '--------------------------------------------------------------------------------------