@@ -32,12 +32,12 @@ int main(void)
32
32
int currentFps = 60 ;
33
33
34
34
// Store the position for the both of the circles
35
- Vector2 deltaCircle = {0 , screenHeight / 3.0f };
36
- Vector2 frameCircle = {0 , screenHeight * (2.0f /3.0f )};
35
+ Vector2 deltaCircle = { 0 , ( float ) screenHeight / 3.0f };
36
+ Vector2 frameCircle = { 0 , ( float ) screenHeight * (2.0f /3.0f ) };
37
37
38
38
// The speed applied to both circles
39
- const float speed = 10.0 ;
40
- const float circleRadius = 32 ;
39
+ const float speed = 10.0f ;
40
+ const float circleRadius = 32.0f ;
41
41
42
42
SetTargetFPS (currentFps );
43
43
//--------------------------------------------------------------------------------------
@@ -46,77 +46,58 @@ int main(void)
46
46
while (!WindowShouldClose ()) // Detect window close button or ESC key
47
47
{
48
48
// Update
49
- //----------------------------------------------
50
- if (IsKeyPressed (KEY_R )) // Reset both circles' positions when you press R
51
- {
52
- deltaCircle .x = 0 ;
53
- frameCircle .x = 0 ;
54
- }
55
-
49
+ //----------------------------------------------------------------------------------
56
50
// Adjust the FPS target based on the mouse wheel
57
51
float mouseWheel = GetMouseWheelMove ();
58
52
if (mouseWheel != 0 )
59
53
{
60
54
currentFps += (int )mouseWheel ;
55
+ if (currentFps < 0 ) currentFps = 0 ;
61
56
SetTargetFPS (currentFps );
62
57
}
63
58
64
59
// GetFrameTime() returns the time it took to draw the last frame, in seconds (usually called delta time)
65
60
// Uses the delta time to make the circle look like it's moving at a "consistent" speed regardless of FPS
66
61
67
- // Multiply by 6.0 (an arbitrary value) in order to make the speed visually closer to the other circle (at 60 fps), for comparison
68
- deltaCircle .x += GetFrameTime () * 6.0f * speed ;
62
+ // Multiply by 6.0 (an arbitrary value) in order to make the speed
63
+ // visually closer to the other circle (at 60 fps), for comparison
64
+ deltaCircle .x += GetFrameTime ()* 6.0f * speed ;
69
65
// This circle can move faster or slower visually depending on the FPS
70
- frameCircle .x += .1f * speed ;
66
+ frameCircle .x += 0 .1f* speed ;
71
67
72
68
// If either circle is off the screen, reset it back to the start
73
- if (deltaCircle .x > screenWidth )
69
+ if (deltaCircle .x > screenWidth ) deltaCircle .x = 0 ;
70
+ if (frameCircle .x > screenWidth ) frameCircle .x = 0 ;
71
+
72
+ // Reset both circles positions
73
+ if (IsKeyPressed (KEY_R ))
74
74
{
75
75
deltaCircle .x = 0 ;
76
- }
77
-
78
- if (frameCircle .x > screenWidth )
79
- {
80
76
frameCircle .x = 0 ;
81
77
}
78
+ //----------------------------------------------------------------------------------
82
79
83
80
// Draw
84
81
//----------------------------------------------------------------------------------
85
82
BeginDrawing ();
86
-
87
- ClearBackground (RAYWHITE );
88
-
89
- // Draw both circles to the screen
90
- DrawCircleV (deltaCircle , circleRadius , RED );
91
- DrawCircleV (frameCircle , circleRadius , BLUE );
92
-
93
- // Determine what help text to show depending on the current FPS target
94
- const char * fpsText ;
95
-
96
- if (currentFps <= 0 )
97
- {
98
- if (currentFps < 0 )
99
- {
100
- // Clamp values below 0
101
- currentFps = 0 ;
102
- }
103
-
104
- // Special text for when the FPS target is set to 0 or less, which makes it unlimited
105
- fpsText = TextFormat ("fps: unlimited (%i)" , GetFPS ());
106
- }
107
- else
108
- {
109
- fpsText = TextFormat ("fps: %i (target: %i)" , GetFPS (), currentFps );
110
- }
111
-
112
- // Draw the help text
113
- DrawText (fpsText , 10 , 10 , 20 , DARKGRAY );
114
- DrawText (TextFormat ("frame time: %02.02f ms" , GetFrameTime ()), 10 , 30 , 20 , DARKGRAY );
115
- DrawText ("use the scroll wheel to change the fps limit, r to reset" , 10 , 50 , 20 , DARKGRAY );
116
-
117
- // Draw the text above the circles
118
- DrawText ("x += GetFrameTime() * speed" , 10 , 90 , 20 , RED );
119
- DrawText ("x += speed" , 10 , 240 , 20 , BLUE );
83
+ ClearBackground (RAYWHITE );
84
+
85
+ // Draw both circles to the screen
86
+ DrawCircleV (deltaCircle , circleRadius , RED );
87
+ DrawCircleV (frameCircle , circleRadius , BLUE );
88
+
89
+ // Draw the help text
90
+ // Determine what help text to show depending on the current FPS target
91
+ const char * fpsText = 0 ;
92
+ if (currentFps <= 0 ) fpsText = TextFormat ("FPS: unlimited (%i)" , GetFPS ());
93
+ else fpsText = TextFormat ("FPS: %i (target: %i)" , GetFPS (), currentFps );
94
+ DrawText (fpsText , 10 , 10 , 20 , DARKGRAY );
95
+ DrawText (TextFormat ("Frame time: %02.02f ms" , GetFrameTime ()), 10 , 30 , 20 , DARKGRAY );
96
+ DrawText ("Use the scroll wheel to change the fps limit, r to reset" , 10 , 50 , 20 , DARKGRAY );
97
+
98
+ // Draw the text above the circles
99
+ DrawText ("FUNC: x += GetFrameTime()*speed" , 10 , 90 , 20 , RED );
100
+ DrawText ("FUNC: x += speed" , 10 , 240 , 20 , BLUE );
120
101
121
102
EndDrawing ();
122
103
//----------------------------------------------------------------------------------
0 commit comments