Initialization

This commit is contained in:
Kozar 2024-04-26 14:13:39 +02:00
parent 04c0ba0717
commit 995af98378

View File

@ -2,21 +2,20 @@
#include <curses.h>
#include <string.h>
#include "world.h"
// Game state structure
struct state {
int width;
int height;
int sx;
int sy;
struct snake* snake;
int foodx[5];
int foody[5];
};
#include "snake.h"
// Initialize game state
void* init_game() {
struct state* st = calloc(1, sizeof(struct state));
st->width = 0;
st->height = 0;
st->sx = 0;
st->sy = 0;
st->snake = NULL;
for (int i = 0; i < 5; i++) {
st->foodx[i] = 0;
st->foody[i] = 0;
}
return st;
}
@ -58,7 +57,7 @@ int world_event(struct event* w, void* game) {
st->sx = 0;
st->sy = -1;
}
} else if (w->type == EVENT_ESC) {
} else if (w->type == EVENT_ESC) {
return 1;
} else if (w->type == EVENT_TIMEOUT) {
clear_screen();