Initialization
This commit is contained in:
parent
04c0ba0717
commit
995af98378
25
a2/snake.c
25
a2/snake.c
@ -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();
|
||||
@ -84,4 +83,4 @@ int world_event(struct event* w, void* game) {
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user