From 412b55caf9f200d1bbe538d3922051e8a6cb2053 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:23:37 +0100 Subject: [PATCH] go --- src/game.h | 9 ++++++++- src/main.c | 19 +++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/game.h b/src/game.h index 7331933..a71f5ae 100644 --- a/src/game.h +++ b/src/game.h @@ -3,9 +3,16 @@ #include "snake.h" #include "food.h" +#include "obstacle.h" // Added for obstacle support +// Game state enum (added but doesn't conflict with existing bool gameOver) +typedef enum { MENU, PLAYING, GAME_OVER } GameState; + +// Your existing functions (unchanged) void HandleInput(Snake *snake); void ResetGame(Snake *snake, Food *food, int *score, bool *gameOver); -#endif +// New version that supports obstacles (doesn't replace the old one) +void ResetGameWithObstacles(Snake *snake, Food *food, Obstacle obstacles[], int *score, GameState *state); +#endif \ No newline at end of file diff --git a/src/main.c b/src/main.c index 1258b82..de63bad 100644 --- a/src/main.c +++ b/src/main.c @@ -1,13 +1,13 @@ #include "raylib.h" #include "snake.h" #include "food.h" -#include "game.h" +#include "game.h" // Now contains GameState enum #include "obstacle.h" #include <stdlib.h> #include <time.h> #include <stdio.h> -typedef enum { MENU, PLAYING, GAME_OVER } GameState; +// Remove the GameState enum - it's now in game.h void HandleFlashEffect(int *flashFrames, Color *flashColor) { if (*flashFrames > 0) { @@ -18,7 +18,8 @@ void HandleFlashEffect(int *flashFrames, Color *flashColor) { } } -void ResetGame(Snake *snake, Food *food, Obstacle obstacles[], int *score, GameState *state) { +// Change the function name to match game.h +void ResetGameWithObstacles(Snake *snake, Food *food, Obstacle obstacles[], int *score, GameState *state) { InitSnake(snake); SpawnFood(food); InitObstacles(obstacles, MAX_OBSTACLES); @@ -26,7 +27,7 @@ void ResetGame(Snake *snake, Food *food, Obstacle obstacles[], int *score, GameS *state = PLAYING; // Spawn initial obstacles - for (int i = 0; i < 5; i++) { // Start with 5 obstacles + for (int i = 0; i < 5; i++) { SpawnObstacle(obstacles, MAX_OBSTACLES, snake, food); } } @@ -63,7 +64,8 @@ int main(void) { switch (gameState) { case MENU: if (IsKeyPressed(KEY_ENTER)) { - ResetGame(&snake, &food, obstacles, &score, &gameState); + // Changed to ResetGameWithObstacles + ResetGameWithObstacles(&snake, &food, obstacles, &score, &gameState); flashColor = PURPLE; flashFrames = 1; } @@ -98,14 +100,15 @@ int main(void) { case GAME_OVER: if (IsKeyPressed(KEY_ENTER)) { - ResetGame(&snake, &food, obstacles, &score, &gameState); + // Changed to ResetGameWithObstacles + ResetGameWithObstacles(&snake, &food, obstacles, &score, &gameState); flashColor = GREEN; flashFrames = 5; } break; } - // Drawing + // ... rest of your drawing code remains exactly the same ... BeginDrawing(); ClearBackground(RAYWHITE); @@ -149,4 +152,4 @@ int main(void) { CloseWindow(); return 0; -} +} \ No newline at end of file -- GitLab