[examples] Move window for ball shake (#5791)

This commit is contained in:
Sebbl0508
2026-04-24 15:09:02 +02:00
committed by GitHub
parent 4cae4ba9d5
commit 61dd488b76

View File

@ -16,6 +16,7 @@
********************************************************************************************/
#include "raylib.h"
#include "raymath.h"
#include <stdlib.h> // Required for: malloc(), free()
#include <math.h> // 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;
}
}