From 7eca1492d0398a1d24aa07dafa2d31080567d434 Mon Sep 17 00:00:00 2001 From: "Ahmet Sungur (Student)" <ahmet2.sungur@live.uwe.ac.uk@csctcloud.prxhn32zsyjupl12zde3wlfkch.cwx.internal.cloudapp.net> Date: Thu, 3 Apr 2025 13:19:09 +0100 Subject: [PATCH] a --- src/main.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/main.c b/src/main.c index 891980b..7b4bfa7 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,3 @@ - #include "snake.h" #include "food.h" #include "game.h" @@ -9,8 +8,7 @@ #include "snake.h" #include "raylib.h" - - +// Creates a flash effect by clearing the screen with a color for a set number of frames void HandleFlashEffect(int *flashFrames, Color *flashColor) { if (*flashFrames > 0) { BeginDrawing(); @@ -20,7 +18,7 @@ void HandleFlashEffect(int *flashFrames, Color *flashColor) { } } - +// Resets the game by initializing snake, food, obstacles, score, level, and state; spawns 5 initial obstacles void ResetGameWithObstacles(Snake *snake, Food *food, Obstacle obstacles[], int *score, int *level, GameState *state) { InitSnake(snake); SpawnFood(food); @@ -35,6 +33,7 @@ void ResetGameWithObstacles(Snake *snake, Food *food, Obstacle obstacles[], int } } +// Main function: Starts the game, runs the game loop, and handles states (MENU, PLAYING, PAUSED, GAME_OVER) int main(void) { InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Snake Game"); SetTargetFPS(10); @@ -63,7 +62,6 @@ int main(void) { continue; } - switch (gameState) { case MENU: if (IsKeyPressed(KEY_ENTER)) { @@ -86,7 +84,7 @@ int main(void) { flashColor = YELLOW; flashFrames = 1; - // Every 5 points, add a new obstacle + // Every 5 points, add a new obstacle, and level += 1 if (score % 5 == 0) { SpawnObstacle(obstacles, MAX_OBSTACLES, &snake, &food); level++; @@ -96,7 +94,7 @@ int main(void) { // Collision checks if (CheckCollision(&snake) || CheckObstacleCollision(&snake, obstacles, MAX_OBSTACLES)) { gameState = GAME_OVER; - flashColor = RED ; + flashColor = RED; flashFrames = 2; } break; @@ -188,19 +186,15 @@ int main(void) { } } - // Replace your food drawing code with: + // Drawing apple DrawCircle(food.position.x * CELL_SIZE + CELL_SIZE/2, food.position.y * CELL_SIZE + CELL_SIZE/2, CELL_SIZE/3, RED); - // Add details to make it look like an apple - DrawCircle(food.position.x * CELL_SIZE + CELL_SIZE/2, - food.position.y * CELL_SIZE + CELL_SIZE/4, - CELL_SIZE/12, BROWN); // Stem + //adding small green circle to make it look like apple DrawCircle(food.position.x * CELL_SIZE + CELL_SIZE/3, food.position.y * CELL_SIZE + CELL_SIZE/3, CELL_SIZE/12, GREEN); // Leaf - DrawObstacles(obstacles, MAX_OBSTACLES) ; - + DrawObstacles(obstacles, MAX_OBSTACLES); //DRAW PAUSE OVERLAY DrawRectangle(0,0, SCREEN_WIDTH, SCREEN_HEIGHT, (Color){0,0,0,128}); @@ -210,8 +204,6 @@ int main(void) { DrawText(TextFormat("Score: %d", score), 10, 40, 20, RED); break; - - // TRIED TO MAKE GAME OVER MENU TEXTS LOOK BETTER :) case GAME_OVER: DrawText("GAME OVER!", SCREEN_WIDTH/2 - 150, SCREEN_HEIGHT/2 - 40, 40, RED); DrawText(TextFormat("Score: %d", score), SCREEN_WIDTH/2 - 120, SCREEN_HEIGHT/2 + 20, 30, RED); -- GitLab