From 61dd488b763ae7b7be47fbd2c8e98c4fec1d3ce6 Mon Sep 17 00:00:00 2001 From: Sebbl0508 <28149337+Sebbl0508@users.noreply.github.com> Date: Fri, 24 Apr 2026 15:09:02 +0200 Subject: [PATCH] [examples] Move window for ball shake (#5791) --- examples/shapes/shapes_ball_physics.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/shapes/shapes_ball_physics.c b/examples/shapes/shapes_ball_physics.c index 2a4cc8f18..2424ea738 100644 --- a/examples/shapes/shapes_ball_physics.c +++ b/examples/shapes/shapes_ball_physics.c @@ -16,6 +16,7 @@ ********************************************************************************************/ #include "raylib.h" +#include "raymath.h" #include // Required for: malloc(), free() #include // Required for: hypot() @@ -68,6 +69,8 @@ int main(void) Vector2 pressOffset = { 0 }; // Mouse press offset relative to the ball that grabbedd float gravity = 100; // World gravity + + Vector2 windowPosition = GetWindowPosition(); SetTargetFPS(60); // Set our game to run at 60 frames-per-second //--------------------------------------------------------------------------------------- @@ -128,6 +131,15 @@ int main(void) } } + Vector2 windowPositionDiff = Vector2Subtract(windowPosition, GetWindowPosition()); + if (Vector2Length(windowPositionDiff) > 5.0f) { + for (int i = 0; i < ballCount; i++) { + if (!balls[i].grabbed) { + balls[i].speed = Vector2Add(balls[i].speed, Vector2Scale(windowPositionDiff, 10.0f)); + } + } + } + // Shake balls if (IsMouseButtonPressed(MOUSE_BUTTON_MIDDLE)) { @@ -194,6 +206,8 @@ int main(void) ball->prevPosition = ball->position; } } + + windowPosition = GetWindowPosition(); //---------------------------------------------------------------------------------- // Draw @@ -226,4 +240,4 @@ int main(void) //-------------------------------------------------------------------------------------- return 0; -} \ No newline at end of file +}