From 42b982c6c436fe8999cb346cab07f720fc4956fe Mon Sep 17 00:00:00 2001 From: Wynd Date: Fri, 5 Sep 2025 00:13:58 +0300 Subject: [PATCH] Added delta time for ball movement --- main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index bff5ccb..360480c 100644 --- a/main.c +++ b/main.c @@ -78,7 +78,7 @@ void BallChangeVelocity(Ball *ball, Vector2 force) { ball->velocity = Vector2Multiply(ball->velocity, BALL_VELOCITY); } -void BallMove(Ball *ball, Player *player) { +void BallMove(Ball *ball, Player *player, float delta_time) { bool isColliding = CheckCollisionRecs(player->shape, ball->shape); if (ball->shape.x < 0 || ball->shape.x + BALL_RADIUS > VIRTUAL_WIDTH) { @@ -125,8 +125,8 @@ void BallMove(Ball *ball, Player *player) { ball->velocityMultiplier = 0.5f; } - ball->shape.x += ball->velocity.x * ball->velocityMultiplier; - ball->shape.y += ball->velocity.y * ball->velocityMultiplier; + ball->shape.x += 50 * ball->velocity.x * ball->velocityMultiplier * delta_time; + ball->shape.y += 50 * ball->velocity.y * ball->velocityMultiplier * delta_time; } int main() { @@ -169,6 +169,8 @@ int main() { int brokenBlocks = 0; while (!WindowShouldClose()) { + float dt = GetFrameTime(); + if (IsKeyDown(KEY_R)) { BallReset(&ball); BlocksReset(blocks); @@ -179,7 +181,7 @@ int main() { DisableCursor(); - BallMove(&ball, &player); + BallMove(&ball, &player, dt); BeginTextureMode(RENDER_TEXTURE); {