Skip to content
Snippets Groups Projects
Commit b51fb5f3 authored by Lalit2.Dangi@live.uwe.ac.uk's avatar Lalit2.Dangi@live.uwe.ac.uk
Browse files

Edit game.c

parent ffc78dc8
Branches
Tags
No related merge requests found
......@@ -23,15 +23,24 @@ void UpdateBall(Ball *ball, Paddle *paddle) {
ball->position.x += ball->speed.x;
ball->position.y += ball->speed.y;
// Bounce off top and bottom walls
if (ball->position.y <= 0 || ball->position.y >= 450) {
// Bounce off top and bottom
if (ball->position.y <= 0 || ball->position.y + ball->radius >= 450) {
ball->speed.y *= -1;
}
// Ball hits paddle
// Bounce off paddle
if (CheckCollisionCircleRec(ball->position, ball->radius, paddle->rect)) {
ball->speed.x *= -1;
ball->score++;
// ✅ Level progression: increase speed every 5 points
if (ball->score % 5 == 0) {
if (ball->speed.x > 0) ball->speed.x += 1;
else ball->speed.x -= 1;
if (ball->speed.y > 0) ball->speed.y += 1;
else ball->speed.y -= 1;
}
}
// Ball missed paddle
......@@ -39,6 +48,9 @@ void UpdateBall(Ball *ball, Paddle *paddle) {
ball->lives--;
ball->position = (Vector2){400, 225};
// Reset to base speed
ball->speed = (Vector2){4, 4};
if (ball->lives <= 0) {
ball->isGameOver = true;
}
......@@ -57,8 +69,3 @@ void DrawGame(Paddle *paddle, Ball *ball) {
DrawText("Press ESC to quit", 300, 250, 20, DARKGRAY);
}
}
void FreeGame(Paddle *paddle, Ball *ball) {
free(paddle);
free(ball);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment