Skip to content
Snippets Groups Projects
Commit b85adf28 authored by Ahmet Sungur (Student)'s avatar Ahmet Sungur (Student)
Browse files

lets go

parent 5028e654
No related branches found
No related tags found
No related merge requests found
......@@ -29,3 +29,17 @@ void ResetGame(Snake *snake, Food *food, int *score, bool *gameOver) {
*gameOver = false;
}
void TogglePause (GameState *state) {
if (*state == PLAYING) {
*state = PAUSED;
} else if (*state == PAUSED) {
*state = PLAYING;
}
}
void HandlePauseInput(GameState * state) {
if (IsKeyPressed(KEY_ESCAPE) || IsKeyPressed(KEY_P)) {
TogglePause(state);
}
}
\ No newline at end of file
......@@ -6,7 +6,7 @@
#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;
typedef enum { MENU, PLAYING, PAUSED, GAME_OVER } GameState;
// Your existing functions (unchanged)
void HandleInput(Snake *snake);
......@@ -14,5 +14,7 @@ void ResetGame(Snake *snake, Food *food, int *score, bool *gameOver);
// New version that supports obstacles (doesn't replace the old one)
void ResetGameWithObstacles(Snake *snake, Food *food, Obstacle obstacles[], int *score, int *level, GameState *state);
void TogglePause(GameState *state);
void HandlePauseInput(GameState *state);
#endif
\ No newline at end of file
......@@ -76,6 +76,7 @@ int main(void) {
case PLAYING:
HandleInput(&snake);
HandlePauseInput(&gameState);
UpdateSnake(&snake);
// Food collision
......@@ -100,6 +101,9 @@ int main(void) {
flashFrames = 2;
}
break;
case PAUSED:
HandlePauseInput(&gameState);
break;
case GAME_OVER:
if (IsKeyPressed(KEY_ENTER)) {
......@@ -142,6 +146,29 @@ int main(void) {
DrawText(TextFormat("Level: %d", level), 10, 40, 20, DARKGRAY);
break;
case PAUSED:
for (int i = 0; i < snake.length; i++){
DrawRectangle(snake.segments[i].x * CELL_SIZE,
snake.segments[i].y * CELL_SIZE,
CELL_SIZE, CELL_SIZE, GREEN);
}
DrawRectangle(food.position.x * CELL_SIZE,
food.position.y * CELL_SIZE,
CELL_SIZE, CELL_SIZE, BLUE);
DrawObstacles(obstacles, MAX_OBSTACLES) ;
//DRAW PAUSE OVERLAY
DrawRectangle(0,0, SCREEN_WIDTH, SCREEN_HEIGHT, (Color){0,0,0,128});
DrawText("Paused", SCREEN_WIDTH/2 -80, SCREEN_HEIGHT/2 -40, 50, WHITE);
DrawText("Press ESC or P to resume", SCREEN_WIDTH/2 -150, SCREEN_HEIGHT/2 +20, 20, WHITE);
DrawText(TextFormat("Level: %d", level), 10, 10, 20, WHITE);
DrawText(TextFormat("Score: %d", score), 10, 40, 20, WHITE);
break;
case GAME_OVER:
DrawText("GAME OVER!", SCREEN_WIDTH/2 - 100, SCREEN_HEIGHT/2 - 40, 40, RED);
DrawText(TextFormat("Score: %d", score), SCREEN_WIDTH/2 - 60, SCREEN_HEIGHT/2 + 20, 30, DARKGRAY);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment