-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnake.ino
More file actions
47 lines (44 loc) · 1.02 KB
/
Snake.ino
File metadata and controls
47 lines (44 loc) · 1.02 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
void handleSnakeInput() {
if (joyState == JoyMovements::JOY_UP) {
if (rowDir != 1) {
nextRowDir = -1;
nextColDir = 0;
}
} else if (joyState == JoyMovements::JOY_DOWN) {
if (rowDir != -1) {
nextRowDir = 1;
nextColDir = 0;
}
} else if (joyState == JoyMovements::JOY_RIGHT) {
if (colDir != -1) {
nextColDir = 1;
nextRowDir = 0;
}
} else if (joyState == JoyMovements::JOY_LEFT) {
if (colDir != 1) {
nextColDir = -1;
nextRowDir = 0;
}
}
}
bool checkInHistory(byte row, byte col) {
byte position = (row << 4) | col;
for (int i = 0; i < snakeHistoryLength; ++i) {
if (snakeHistory[i] == position) {
return true;
}
}
return false;
}
byte historyPop() {
byte temp = snakeHistory[0];
for (int i = 0; i < snakeHistoryLength; ++i) {
snakeHistory[i] = snakeHistory[i + 1];
}
snakeHistoryLength--;
return temp;
}
void historyPush(int row, int col) {
snakeHistory[snakeHistoryLength] = (row << 4) | col;
snakeHistoryLength++;
}