1717********************************************************************************************/
1818
1919#include "raylib.h"
20- #include "raymath.h"
20+
21+ #include "raymath.h" // Required for: Clamp()
2122
2223//------------------------------------------------------------------------------------
2324// Program main entry point
@@ -33,18 +34,14 @@ int main(void)
3334
3435 Texture2D booth = LoadTexture ("resources/booth.png" );
3536
36- // The overall scale of the stacked sprite
37- float stackScale = 3.0f ;
38- // The vertical spacing between each layer
39- float stackSpacing = 2.0f ;
40- // The number of layers. Used for calculating the size of a single slice
41- unsigned int stackCount = 122 ;
42- // The speed to rotate the stacked sprite
43- float rotationSpeed = 30.0f ;
44- // The current rotation of the stacked sprite
45- float rotation = 0.0f ;
46- // The amount that speed will change by when the user presses A/D
47- const float speedChange = 0.25f ;
37+ float stackScale = 3.0f ; // Overall scale of the stacked sprite
38+ float stackSpacing = 2.0f ; // Vertical spacing between each layer
39+ unsigned int stackCount = 122 ; // Number of layers, used for calculating the size of a single slice
40+ float rotationSpeed = 30.0f ; // Stacked sprites rotation speed
41+ float rotation = 0.0f ; // Current rotation of the stacked sprite
42+ const float speedChange = 0.25f ; // Amount speed will change by when the user presses A/D
43+
44+ SetTargetFPS (60 );
4845 //--------------------------------------------------------------------------------------
4946
5047 // Main game loop
@@ -57,22 +54,16 @@ int main(void)
5754 stackSpacing = Clamp (stackSpacing , 0.0f , 5.0f );
5855
5956 // Add a positive/negative offset to spin right/left at different speeds
60- if (IsKeyDown (KEY_LEFT ) || IsKeyDown (KEY_A ))
61- {
62- rotationSpeed -= speedChange ;
63- }
64-
65- if (IsKeyDown (KEY_RIGHT ) || IsKeyDown (KEY_D ))
66- {
67- rotationSpeed += speedChange ;
68- }
69-
70- rotation += rotationSpeed * GetFrameTime ();
57+ if (IsKeyDown (KEY_LEFT ) || IsKeyDown (KEY_A )) rotationSpeed -= speedChange ;
58+ if (IsKeyDown (KEY_RIGHT ) || IsKeyDown (KEY_D )) rotationSpeed += speedChange ;
59+
60+ rotation += rotationSpeed * GetFrameTime ();
7161 //----------------------------------------------------------------------------------
7262
7363 // Draw
7464 //----------------------------------------------------------------------------------
7565 BeginDrawing ();
66+
7667 ClearBackground (RAYWHITE );
7768
7869 // Get the size of a single slice
@@ -86,20 +77,19 @@ int main(void)
8677 // Draw the stacked sprite, rotated to the correct angle, with an vertical offset applied based on its y location
8778 for (int i = stackCount - 1 ; i >= 0 ; i -- )
8879 {
89- Rectangle source = { 0.0f , (float )i * frameHeight , frameWidth , frameHeight };
9080 // Center vertically
81+ Rectangle source = { 0.0f , (float )i * frameHeight , frameWidth , frameHeight };
9182 Rectangle dest = { screenWidth /2.0f , (screenHeight /2.0f ) + (i * stackSpacing ) - (stackSpacing * stackCount /2.0f ), scaledWidth , scaledHeight };
9283 Vector2 origin = { scaledWidth /2.0f , scaledHeight /2.0f };
9384
9485 DrawTexturePro (booth , source , dest , origin , rotation , WHITE );
9586 }
9687
97- DrawText ("a/d to spin\nmouse wheel to change separation (aka 'angle')" , 10 , 10 , 20 , DARKGRAY );
98- const char * spacingText = TextFormat ("current spacing: %.01f" , stackSpacing );
99- DrawText (spacingText , 10 , 50 , 20 , DARKGRAY );
100- const char * speedText = TextFormat ("current speed: %.02f" , rotationSpeed );
101- DrawText (speedText , 10 , 70 , 20 , DARKGRAY );
88+ DrawText ("A/D to spin\nmouse wheel to change separation (aka 'angle')" , 10 , 10 , 20 , DARKGRAY );
89+ DrawText (TextFormat ("current spacing: %.01f" , stackSpacing ), 10 , 50 , 20 , DARKGRAY );
90+ DrawText (TextFormat ("current speed: %.02f" , rotationSpeed ), 10 , 70 , 20 , DARKGRAY );
10291 DrawText ("redbooth model (c) kluchek under cc 4.0" , 10 , 420 , 20 , DARKGRAY );
92+
10393 EndDrawing ();
10494 //----------------------------------------------------------------------------------
10595 }
0 commit comments