Skip to content

Commit d892f3b

Browse files
committed
Update shapes_ball_physics.c
1 parent 61dd488 commit d892f3b

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

examples/shapes/shapes_ball_physics.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
********************************************************************************************/
1717

1818
#include "raylib.h"
19+
1920
#include "raymath.h"
2021

2122
#include <stdlib.h> // Required for: malloc(), free()
@@ -131,12 +132,14 @@ int main(void)
131132
}
132133
}
133134

134-
Vector2 windowPositionDiff = Vector2Subtract(windowPosition, GetWindowPosition());
135-
if (Vector2Length(windowPositionDiff) > 5.0f) {
136-
for (int i = 0; i < ballCount; i++) {
137-
if (!balls[i].grabbed) {
138-
balls[i].speed = Vector2Add(balls[i].speed, Vector2Scale(windowPositionDiff, 10.0f));
139-
}
135+
// Get window position change for shaking
136+
Vector2 windowPositionDelta = Vector2Subtract(windowPosition, GetWindowPosition());
137+
138+
if (Vector2Length(windowPositionDelta) > 5.0f)
139+
{
140+
for (int i = 0; i < ballCount; i++)
141+
{
142+
if (!balls[i].grabbed) balls[i].speed = Vector2Add(balls[i].speed, Vector2Scale(windowPositionDelta, 10.0f));
140143
}
141144
}
142145

@@ -236,6 +239,7 @@ int main(void)
236239
// De-Initialization
237240
//--------------------------------------------------------------------------------------
238241
RL_FREE(balls);
242+
239243
CloseWindow(); // Close window and OpenGL context
240244
//--------------------------------------------------------------------------------------
241245

0 commit comments

Comments
 (0)