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 <curses.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
#include "snake.h"
|
||||||
// Game state structure
|
|
||||||
struct state {
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
int sx;
|
|
||||||
int sy;
|
|
||||||
struct snake* snake;
|
|
||||||
int foodx[5];
|
|
||||||
int foody[5];
|
|
||||||
};
|
|
||||||
|
|
||||||
// Initialize game state
|
// Initialize game state
|
||||||
void* init_game() {
|
void* init_game() {
|
||||||
struct state* st = calloc(1, sizeof(struct state));
|
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;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +57,7 @@ int world_event(struct event* w, void* game) {
|
|||||||
st->sx = 0;
|
st->sx = 0;
|
||||||
st->sy = -1;
|
st->sy = -1;
|
||||||
}
|
}
|
||||||
} else if (w->type == EVENT_ESC) {
|
} else if (w->type == EVENT_ESC) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (w->type == EVENT_TIMEOUT) {
|
} else if (w->type == EVENT_TIMEOUT) {
|
||||||
clear_screen();
|
clear_screen();
|
||||||
@ -84,4 +83,4 @@ int world_event(struct event* w, void* game) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user