-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSnake.h
More file actions
47 lines (34 loc) · 1.1 KB
/
Snake.h
File metadata and controls
47 lines (34 loc) · 1.1 KB
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
#include "App.h"
#include "Shapes.h"
#include "GFXConstants.h"
class Kernel;
enum SnakeDir {
SNAKE_NONE,
SNAKE_UP, SNAKE_DOWN, SNAKE_LEFT, SNAKE_RIGHT,
};
const unsigned short snake_dim = 5; // Given current viewbox_wh, this gives a 25x25 grid
const double spm = 1.5; // Seconds per move (0.5 -> move twice in one second)
const int border_space = 1; // Spacing between apple and border when generating
SnakeDir getdirFromJoystick(double x, double y);
// Linkeduhlist
struct SnakePart {
RectInt part = RectInt{center_x - center_x%snake_dim - snake_dim, center_y - center_y%snake_dim - snake_dim, snake_dim, snake_dim};
SnakeDir dir = SNAKE_NONE;
SnakePart* next = nullptr;
};
class Snake : public App {
Kernel* kernel;
SnakePart* head = nullptr;
RectInt apple = RectInt{0, 0, snake_dim, snake_dim};
bool last_x = false;
bool last_y = false;
double time_since_last_move = 0.0;
public:
Snake(Kernel* kernel);
~Snake();
void run_code(double x, double y, bool special);
void delete_snake();
SnakeDir getdirFromJoystick(double x, double y);
void move_apple();
String get_name();
};