-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDraw.ino
More file actions
65 lines (61 loc) · 1.65 KB
/
Draw.ino
File metadata and controls
65 lines (61 loc) · 1.65 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
void resetDrawScreen() {
clearScreen();
for (int i = 0; i<MAX_LEVEL; i++) {
tail[i][0] = -1;
tail[i][1] = matrix.Color333(0, 7, 0);
food[i] = -1;
}
currentX = 8;
currentY = 16;
currentSnakeSize = 0;
color1 = matrix.Color333(0, 7, 0);
color2 = matrix.Color333(7, 0, 0);
color3 = matrix.Color333(0, 0, 7);
color4 = matrix.Color333(0, 0, 0); //Eraser
selectedColor = color1;
timerStart = millis();
}
void draw(int currentPos) {
if (timeRanout) {
delay(200);
matrix.drawLine(0, 15, 32, 15, matrix.Color333(0, 0, 0));
delay(200);
matrix.drawLine(0, 15, 32, 15, matrix.Color333(7, 0, 0));
}
if (key1bouce) {
delay(500); key1bouce = false;
}
if (key2bouce) {
delay(500); key2bouce = false;
}
if (key3bouce) {
delay(500); key3bouce = false;
}
if (key4bouce) {
delay(500); key4bouce = false;
}
if (currentPos != tail[0][0]) {
if (!isTouchingTheTail(currentPos)) {
if (selectedColor != matrix.Color333(0, 0, 0)) {
currentSnakeSize = currentSnakeSize + 1;
addToTail(currentPos, selectedColor);
}
} else {
//touching
if (selectedColor == matrix.Color333(0, 0, 0)) {
//delete
deleteFromTail(currentPos);
}
}
//set the currentPos
if (currentSnakeSize > MAX_LEVEL) {
delay(3000);
resetDrawScreen();
game = -1;
}
delay(40);
}
int row = currentPos % 16; //y axis (0 to 7)
int col = currentPos / 16; //x axis (0 to 31)
blinkLED(col, row, selectedColor);
}