mirror of
https://github.com/raysan5/raylib.git
synced 2026-04-25 08:13:58 -04:00
[examples] Move window for ball shake (#5791)
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user