funguje
This commit is contained in:
parent
5c64e5e1b0
commit
b10ff342ba
18
a2/snake.c
18
a2/snake.c
@ -64,3 +64,21 @@ int handle_collision(struct state* state) {
|
|||||||
return END_CONTINUE;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user