From 0ae93cfc225c629d83db089053969ae73f01667e Mon Sep 17 00:00:00 2001 From: "Ahmet Sungur (Student)" <ahmet2.sungur@live.uwe.ac.uk@csctcloud.prxhn32zsyjupl12zde3wlfkch.cwx.internal.cloudapp.net> Date: Wed, 2 Apr 2025 14:11:50 +0100 Subject: [PATCH] trying --- src/food.c | 1 + src/game.c | 1 + src/game.h | 1 + src/main.c | 2 +- src/obstacle.c | 21 ++++++++++++--------- src/obstacle.h | 2 ++ src/snake.c | 2 +- src/snake.h | 1 + 8 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/food.c b/src/food.c index 2050903..09447e0 100644 --- a/src/food.c +++ b/src/food.c @@ -6,3 +6,4 @@ void SpawnFood(Food *food) { food->position.x = rand() % (SCREEN_WIDTH / CELL_SIZE); food->position.y = rand() % (SCREEN_HEIGHT / CELL_SIZE); } + diff --git a/src/game.c b/src/game.c index 6c7bb6b..d8878d1 100644 --- a/src/game.c +++ b/src/game.c @@ -28,3 +28,4 @@ void ResetGame(Snake *snake, Food *food, int *score, bool *gameOver) { *score = 0; *gameOver = false; } + diff --git a/src/game.h b/src/game.h index 9a7978f..7331933 100644 --- a/src/game.h +++ b/src/game.h @@ -8,3 +8,4 @@ void HandleInput(Snake *snake); void ResetGame(Snake *snake, Food *food, int *score, bool *gameOver); #endif + diff --git a/src/main.c b/src/main.c index 7f236cb..04f8318 100644 --- a/src/main.c +++ b/src/main.c @@ -148,4 +148,4 @@ int main(void) { CloseWindow(); return 0; -} \ No newline at end of file +} diff --git a/src/obstacle.c b/src/obstacle.c index d09aa0d..9cdc035 100644 --- a/src/obstacle.c +++ b/src/obstacle.c @@ -1,5 +1,8 @@ #include "obstacle.h" #include <stdlib.h> +#include "snake.h" +#include "game.h" +#include "food.h" void InitObstacles(Obstacle obstacles[], int count) { for (int i = 0; i < count; i++) { @@ -65,13 +68,13 @@ void DrawObstacles(const Obstacle obstacles[], int count) { } bool CheckObstacleCollision(const Snake *snake, const Obstacle obstacles[], int count) { - Vector2 head = snake->segments[0]; - for (int i = 0; i < count; i++) { - if (obstacles[i].active && - head.x == obstacles[i].position.x && - head.y == obstacles[i].position.y) { - return true; - } - } - return false; + Position head = snake->segments[0]; // Use Position instead of Vector2 + for (int i = 0; i < count; i++) { + if (obstacles[i].active && + head.x == obstacles[i].position.x && + head.y == obstacles[i].position.y) { + return true; + } + } + return false; } \ No newline at end of file diff --git a/src/obstacle.h b/src/obstacle.h index d25d24f..a9ea5f5 100644 --- a/src/obstacle.h +++ b/src/obstacle.h @@ -2,6 +2,8 @@ #define OBSTACLE_H #include "raylib.h" +#include "snake.h" +#include "food.h" #define MAX_OBSTACLES 20 #define OBSTACLE_COLOR RED diff --git a/src/snake.c b/src/snake.c index 8204c22..e774e12 100644 --- a/src/snake.c +++ b/src/snake.c @@ -37,4 +37,4 @@ bool CheckCollision(Snake *snake) { return true; } return false; -} +} \ No newline at end of file diff --git a/src/snake.h b/src/snake.h index dbc0949..f01345e 100644 --- a/src/snake.h +++ b/src/snake.h @@ -25,3 +25,4 @@ void UpdateSnake(Snake *snake); bool CheckCollision(Snake *snake); #endif + -- GitLab