-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnake.h
55 lines (47 loc) · 1.12 KB
/
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 "game.h"
#define MAX_SNAKE_LENGTH 256
#define SPEED 500 // ms
typedef struct {
int angle;
bool is_turn;
bool should_flip_vertical;
bool should_flip_horizontal;
int turn_rotation;
Pos pos;
} Body_Part;
typedef struct {
int angle;
bool has_turned;
bool mouth_open;
bool mouth_eating;
Pos pos;
} Head_Part;
enum Dir {
None, // None is used to indicate that there is no next direction for snake.next_dir
Up,
Down,
Left,
Right
};
typedef struct {
int body_length;
int speed;
int vel_x;
int vel_y;
int angle;
enum Dir dir;
enum Dir next_dir; // used to wait for snake to be aligned with 32x32 grid before changing velocity
Head_Part head;
Body_Part body[MAX_SNAKE_LENGTH];
Body_Part tail;
} Snake;
Snake *new_snake(int player_nr);
void change_snake_velocity(Snake *snake);
void new_snake_pos(Snake *snake);
Body_Part new_snake_body_part(Pos *last_body_part_pos, int angle, int *body_length);
bool collison_with_wall(Snake *snake);
bool collison_with_snake(Snake *snake);
#endif