From 8344c80fac121e0160f7442c49cd53f000ec7313 Mon Sep 17 00:00:00 2001
From: "Lalit2.Dangi@live.uwe.ac.uk" <lalit2.dangi@live.uwe.ac.uk>
Date: Tue, 1 Apr 2025 09:15:41 +0000
Subject: [PATCH] game.c

---
 game.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 game.c

diff --git a/game.c b/game.c
new file mode 100644
index 0000000..b2de0e4
--- /dev/null
+++ b/game.c
@@ -0,0 +1,40 @@
+#include "game.h"
+#include <stdlib.h>
+
+Paddle *CreatePaddle(float x, float y, float width, float height, int speed) {
+    Paddle *p = (Paddle *)malloc(sizeof(Paddle));
+    p->rect = (Rectangle){x, y, width, height};
+    p->speed = speed;
+    return p;
+}
+
+Ball *CreateBall(float x, float y, int radius, float speedX, float speedY) {
+    Ball *b = (Ball *)malloc(sizeof(Ball));
+    b->position = (Vector2){x, y};
+    b->speed = (Vector2){speedX, speedY};
+    b->radius = radius;
+    return b;
+}
+
+void UpdateBall(Ball *ball, Paddle *paddle) {
+    ball->position.x += ball->speed.x;
+    ball->position.y += ball->speed.y;
+
+    if (ball->position.y <= 0 || ball->position.y >= 450) {
+        ball->speed.y *= -1;
+    }
+
+    if (CheckCollisionCircleRec(ball->position, ball->radius, paddle->rect)) {
+        ball->speed.x *= -1;
+    }
+}
+
+void DrawGame(Paddle *paddle, Ball *ball) {
+    DrawRectangleRec(paddle->rect, BLUE);
+    DrawCircleV(ball->position, ball->radius, RED);
+}
+
+void FreeGame(Paddle *paddle, Ball *ball) {
+    free(paddle);
+    free(ball);
+}
-- 
GitLab