diff --git a/src/game.h b/src/game.h index 73319333aadb6acac8381b1ba054e20a5ffd41fa..a71f5aecbaafdf724e754402f355115a76853bf8 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 1258b827f22ba48f2b9223ff3f8ec47f2093c49e..de63bad6021691d7106f17d8e059b3bea2df3c90 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