-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEatTheDot.ino
95 lines (87 loc) · 1.63 KB
/
EatTheDot.ino
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <M5StickC.h>
float pitch = 0;
float roll = 0;
float yaw = 0;
int x = 40; //Start position for player
int y = 10;
int r = 1;
int foodx = 158; //Start Position of food
int foody = 78;
int foodx1 = 159; //Counter for edge of screen
int foody1 = 79;
void setup() {
M5.begin();
M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(BLACK);
M5.MPU6886.Init();
}
void loop() {
M5.MPU6886.getAhrsData(&pitch, &roll, &yaw);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.drawCircle(x, y, r, RED);
M5.Lcd.drawCircle(foodx, foody, 1, GREEN);
if (roll > -25) { //read MPU roll data for left and right
x--;
}
if (roll < -5) {
x++;
}
if (pitch > -15) { //read MPU pitch data for up and down
y++;
}
if (pitch < -1) {
y--;
}
if (x < 0) { //keeps player inbounds
x = 1;
}
if (x > 160) {
x = 159;
}
if (y < 0) {
y = 1;
}
if (y > 80) {
y = 79;
}
if (foodx < foodx1) { //moves food
foodx1 = foodx;
foodx--;
}
if (foodx == 1) { //keeps food inbounds
foodx1 = 0;
}
if (foodx > foodx1) {
foodx1 = foodx;
foodx++;
}
if (foodx == 158) {
foodx1 = 159;
}
if (foody < foody1) {
foody1 = foody;
foody--;
}
if (foody == 1) {
foody1 = 0;
}
if (foody > foody1) {
foody1 = foody;
foody++;
}
if (foody == 78) {
foody1 = 79;
}
if ((foodx <= x + r + 1 && foodx >= x - r -1) && (foody <= y + r + 1 && foody >= y - r -1)) { //detects collision
r++;
foodx = random(2, 158);
foody = random(2, 78);
}
if (digitalRead(M5_BUTTON_HOME) == LOW) { //cheat button
r++;
}
if (r == 50) {
r = 2;
}
delay(50); //set speed of game
}