forked from alexxsxnchez/BrickBreaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.ino
74 lines (68 loc) · 1.54 KB
/
game.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
static int lives;
void gameInit() {
lives = INIT_LIVES;
initBricks();
initPaddle();
initBall();
draw();
delay(GAME_START_DELAY);
}
void loseLife() {
uint32_t totalLivesLost = getValue(LIVES_LOST_ADDRESS);
totalLivesLost++;
updateValue(totalLivesLost, LIVES_LOST_ADDRESS); // update the stats stored in the EEPROM
lives--;
}
void extraLife() {
if(lives >= MAX_LIVES) {
return;
}
lives++;
flashLED(GREEN_LED, 1);
}
void drawLifeCounter() {
OrbitOledMoveTo(1, 0);
OrbitOledSetFillPattern(OrbitOledGetStdPattern(iptnBlank));
OrbitOledFillRect(1, OLED_HEIGHT - 1);
OrbitOledSetFillPattern(OrbitOledGetStdPattern(iptnSolid));
for(int i = 0; i < lives; i++) {
OrbitOledMoveTo(1, i * 3 + 2);
OrbitOledFillRect(1, i * 3 + 2);
}
}
void respawn() {
showBall(false);
showPaddle(false);
if(lifeAvailable()) {
showLife(false);
setLifeAvailable(false);
}
initPaddle();
initBall();
flashLED(RED_LED, 5);
OrbitOledUpdate();
}
void draw() {
drawBricks();
drawPaddle();
drawLifeCounter();
drawBall();
if(lifeAvailable()) {
drawLife();
}
OrbitOledUpdate();
if(lives <= 0) {
newMode(GAME_OVER);
}
else if(getBrickCount() <= 0) {
newMode(GAME_WIN);
}
}
unsigned long refreshScreen(unsigned long sinceRefresh) {
unsigned long timeNow = millis();
if(timeNow - sinceRefresh >= REFRESH_RATE) {
draw();
return timeNow;
}
return sinceRefresh;
}