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