shapes_easings_rectangle_array.bmx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. SuperStrict
  2. Framework Ray.Lib
  3. Const RECS_WIDTH:Int = 50
  4. Const RECS_HEIGHT:Int = 50
  5. Const MAX_RECS_X:Int = 800/RECS_WIDTH
  6. Const MAX_RECS_Y:Int = 450/RECS_HEIGHT
  7. Const PLAY_TIME_IN_FRAMES:Int = 240 ' At 60 fps = 4 seconds
  8. ' Initialization
  9. '--------------------------------------------------------------------------------------
  10. Const screenWidth:Int = 800
  11. Const screenHeight:Int = 450
  12. InitWindow(screenWidth, screenHeight, "raylib [shapes] example - easings rectangle array")
  13. Local recs:RRectangle[MAX_RECS_X*MAX_RECS_Y]
  14. For Local y:Int = 0 Until MAX_RECS_Y
  15. For Local x:Int = 0 Until MAX_RECS_X
  16. recs[y*MAX_RECS_X + x].x = RECS_WIDTH/2 + RECS_WIDTH*x
  17. recs[y*MAX_RECS_X + x].y = RECS_HEIGHT/2 + RECS_HEIGHT*y
  18. recs[y*MAX_RECS_X + x].width = RECS_WIDTH
  19. recs[y*MAX_RECS_X + x].height = RECS_HEIGHT
  20. Next
  21. Next
  22. Local Rotation:Float = 0.0
  23. Local framesCounter:Int = 0
  24. Local state:Int = 0 ' Rectangles animation state: 0-Playing, 1-Finished
  25. SetTargetFPS(60) ' Set our game to run at 60 frames-per-second
  26. '--------------------------------------------------------------------------------------
  27. ' Main game loop
  28. While Not WindowShouldClose() ' Detect window close button or ESC key
  29. ' Update
  30. '----------------------------------------------------------------------------------
  31. If state = 0 Then
  32. framesCounter :+ 1
  33. For Local i:Int = 0 Until MAX_RECS_X*MAX_RECS_Y
  34. recs[i].height = EaseCircOut(framesCounter, RECS_HEIGHT, -RECS_HEIGHT, PLAY_TIME_IN_FRAMES)
  35. recs[i].width = EaseCircOut(framesCounter, RECS_WIDTH, -RECS_WIDTH, PLAY_TIME_IN_FRAMES)
  36. If recs[i].height < 0 Then
  37. recs[i].height = 0
  38. End If
  39. If recs[i].width < 0 Then
  40. recs[i].width = 0
  41. End If
  42. If (recs[i].height = 0) And (recs[i].width = 0) Then
  43. state = 1 ' Finish playing
  44. End If
  45. Rotation = EaseLinearIn(framesCounter, 0.0, 360.0, PLAY_TIME_IN_FRAMES)
  46. Next
  47. Else If (state = 1) And IsKeyPressed(KEY_SPACE) Then
  48. ' When animation has finished, press space to restart
  49. framesCounter = 0
  50. For Local i:Int = 0 Until MAX_RECS_X*MAX_RECS_Y
  51. recs[i].height = RECS_HEIGHT
  52. recs[i].width = RECS_WIDTH
  53. Next
  54. state = 0
  55. End If
  56. '----------------------------------------------------------------------------------
  57. ' Draw
  58. '----------------------------------------------------------------------------------
  59. BeginDrawing()
  60. ClearBackground(RAYWHITE)
  61. If state = 0 Then
  62. For Local i:Int = 0 Until MAX_RECS_X*MAX_RECS_Y
  63. DrawRectanglePro(recs[i], New RVector2(recs[i].width/2, recs[i].height/2), Rotation, RED)
  64. Next
  65. Else If state = 1 Then
  66. DrawText("PRESS [SPACE] TO PLAY AGAIN!", 240, 200, 20, GRAY)
  67. End If
  68. EndDrawing()
  69. '----------------------------------------------------------------------------------
  70. Wend
  71. ' De-Initialization
  72. '--------------------------------------------------------------------------------------
  73. CloseWindow() ' Close window and OpenGL context
  74. '--------------------------------------------------------------------------------------