From b10ff342ba7fcd39e735c0c3d0beffceb9835a65 Mon Sep 17 00:00:00 2001 From: st529yr Date: Mon, 8 Apr 2024 15:46:50 +0200 Subject: [PATCH] funguje --- a2/snake.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/a2/snake.c b/a2/snake.c index a6d30e8..3ca2d87 100644 --- a/a2/snake.c +++ b/a2/snake.c @@ -64,3 +64,21 @@ int handle_collision(struct state* state) { return END_CONTINUE; } +// Function to initialize the game world +void initialize_world(struct state* state) { + // Initialize random seed + srand(time(NULL)); + + // Place the snake in the center of the game area + state->snake = malloc(sizeof(struct snake)); + state->snake->x = state->width / 2; + state->snake->y = state->height / 2; + state->snake->next = NULL; + + // Place 20 food items randomly in the game area + for (int i = 0; i < FOOD_COUNT; i++) { + state->foodx[i] = rand() % state->width; + state->foody[i] = rand() % state->height; + } +} +