-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoutine.h
80 lines (56 loc) · 1.71 KB
/
Routine.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef _routine_h_
#define _routine_h_
#include "Display.h"
//#define DEBUG 1
/* joystick switch (click) pin (unused) */
#define JS_S_PIN 8
/* joystick x axis pin */
#define JS_X_PIN 0
/* joystick y axis pin */
#define JS_Y_PIN 1
/* random seed floating pin */
#define RANDOMSEED_PIN 2
#define BASE_DELAY 100
#define SNAKE_INIT_LENGTH 10
#define SNAKE_MAX_LENGTH 100
#define FOOD_INIT_LENGTH 10
#define FOOD_MAX_LENGTH 200
class Routine {
public:
/* Initialize the game */
static void Initialize();
/* Implements each frame of the game logic */
static void Step();
private:
/* Game state */
/* Array of x,y positions the snake is currently in and its length */
static uint8_t snake[][2];
static uint16_t snakeLength;
/* Array of x,y positions the food pieces are currently in and its length */
static uint8_t food[][2];
static uint16_t foodLength;
/* Game level and score */
static uint8_t level;
static uint16_t score;
/* Snake's head position and current direction */
static uint8_t cursor_x;
static uint8_t cursor_y;
static uint8_t cursor_d;
/* Initialize a new level */
static void NewLevel();
/* Read joystick input */
static void ReadInput();
/* Test if snake has collided with itself or a barrier */
static bool IsCollision();
/* Add a new element to the head of the snake */
static void AddSnake();
/* Pop an element from the back of the snakeLength */
static void PopSnake();
/* Add a food item to a random screen position */
static void AddFood();
/* Remove the food item at the cursor's position from the food array, if it exists. returns false if it doesn't. */
static bool EatFood();
/* Game over screen */
static void GameOver();
};
#endif