This commit is contained in:
Tančáková 2024-04-08 15:46:50 +02:00
parent 5c64e5e1b0
commit b10ff342ba

View File

@ -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;
}
}