Added delta time for ball movement

master
Wynd 2025-09-05 00:13:58 +03:00
parent deddb6ae98
commit 42b982c6c4
1 changed files with 6 additions and 4 deletions

10
main.c
View File

@ -78,7 +78,7 @@ void BallChangeVelocity(Ball *ball, Vector2 force) {
ball->velocity = Vector2Multiply(ball->velocity, BALL_VELOCITY); 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); bool isColliding = CheckCollisionRecs(player->shape, ball->shape);
if (ball->shape.x < 0 || ball->shape.x + BALL_RADIUS > VIRTUAL_WIDTH) { 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->velocityMultiplier = 0.5f;
} }
ball->shape.x += ball->velocity.x * ball->velocityMultiplier; ball->shape.x += 50 * ball->velocity.x * ball->velocityMultiplier * delta_time;
ball->shape.y += ball->velocity.y * ball->velocityMultiplier; ball->shape.y += 50 * ball->velocity.y * ball->velocityMultiplier * delta_time;
} }
int main() { int main() {
@ -169,6 +169,8 @@ int main() {
int brokenBlocks = 0; int brokenBlocks = 0;
while (!WindowShouldClose()) { while (!WindowShouldClose()) {
float dt = GetFrameTime();
if (IsKeyDown(KEY_R)) { if (IsKeyDown(KEY_R)) {
BallReset(&ball); BallReset(&ball);
BlocksReset(blocks); BlocksReset(blocks);
@ -179,7 +181,7 @@ int main() {
DisableCursor(); DisableCursor();
BallMove(&ball, &player); BallMove(&ball, &player, dt);
BeginTextureMode(RENDER_TEXTURE); BeginTextureMode(RENDER_TEXTURE);
{ {