From ffc78dc8425e480a37f6125da03a4926653e95a9 Mon Sep 17 00:00:00 2001
From: "Lalit2.Dangi@live.uwe.ac.uk" <lalit2.dangi@live.uwe.ac.uk>
Date: Fri, 4 Apr 2025 10:29:57 +0000
Subject: [PATCH] Edit game.c

---
 game.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/game.c b/game.c
index c5978ef..1f05b3d 100644
--- a/game.c
+++ b/game.c
@@ -13,29 +13,49 @@ Ball *CreateBall(float x, float y, int radius, float speedX, float speedY) {
     b->position = (Vector2){x, y};
     b->speed = (Vector2){speedX, speedY};
     b->radius = radius;
+    b->score = 0;
+    b->lives = 3;
+    b->isGameOver = false;
     return b;
 }
-b->score = 0;  // ✅ Start score at 0
 
 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) {
         ball->speed.y *= -1;
     }
 
+    // Ball hits paddle
     if (CheckCollisionCircleRec(ball->position, ball->radius, paddle->rect)) {
-    ball->speed.x *= -1;
-    ball->score++;  // ✅ Increase score when ball hits paddle
-}
+        ball->speed.x *= -1;
+        ball->score++;
+    }
 
+    // Ball missed paddle
+    if (ball->position.x < 0) {
+        ball->lives--;
+        ball->position = (Vector2){400, 225};
+
+        if (ball->lives <= 0) {
+            ball->isGameOver = true;
+        }
+    }
+}
 
 void DrawGame(Paddle *paddle, Ball *ball) {
     DrawRectangleRec(paddle->rect, BLUE);
     DrawCircleV(ball->position, ball->radius, RED);
+
     DrawText(TextFormat("Score: %d", ball->score), 10, 10, 20, DARKGRAY);
+    DrawText(TextFormat("Lives: %d", ball->lives), 10, 40, 20, MAROON);
 
+    if (ball->isGameOver) {
+        DrawText("GAME OVER", 300, 200, 40, RED);
+        DrawText("Press ESC to quit", 300, 250, 20, DARKGRAY);
+    }
 }
 
 void FreeGame(Paddle *paddle, Ball *ball) {
-- 
GitLab