-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnake.h
55 lines (40 loc) · 937 Bytes
/
snake.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef SNAKE_H_
#define SNAKE_H_
#include <stdbool.h>
#include "sdl_system.h"
extern Color wht;
extern Color blk;
extern Color red;
extern Color grn;
enum Direction { UP, RIGHT, DOWN, LEFT };
// Snake is measured in game Grid Units.
typedef struct Pos_Block
{
int x, y;
struct Pos_Block* next;
struct Pos_Block* prev;
} Pos_Block;
typedef struct Snake
{
Pos_Block* body;
Pos_Block* head;
Pos_Block* tail;
int width, height, size;
enum Direction dir;
bool alive;
} Snake;
enum Obj { EMPTY, PLAYER, APPLE };
void init();
void snake_init();
void cleanup();
bool process_input();
void assign_position(Pos_Block* block, int x, int y);
SDL_Rect to_render_units(Pos_Block* pos, Snake* snk);
void paint_map(Pos_Block* pos, enum Obj o);
void move(Snake* snk);
void rotate(Snake* snk);
void gen_apple();
bool ate_apple(Snake* snk);
void clear_apple(Snake* snk);
bool killed(Snake* snk);
#endif