forked from alexxsxnchez/BrickBreaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extraLife.ino
69 lines (65 loc) · 1.6 KB
/
extraLife.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
static life lifeObj;
static life *lifePtr = &lifeObj;
static bool extraLifeAvailable = false;
void initLife(int x, int y) {
lifePtr -> x = x;
lifePtr -> y = y;
extraLifeAvailable = true;
}
void drawLife() {
bool lifeLost = extraLifeCollision();
showLife(false);
if(lifeLost) {
extraLifeAvailable = false;
return;
}
lifePtr -> y += LIFE_SPEED;
showLife(true);
}
void showLife(boolean makeVisible) {
int pattern;
if(makeVisible) {
pattern = iptnSolid;
}
else {
pattern = iptnBlank;
}
OrbitOledSetFillPattern(OrbitOledGetStdPattern(pattern));
int x = lifePtr -> x;
int y = lifePtr -> y;
OrbitOledMoveTo(y, x);
OrbitOledFillRect(y + LIFE_SIZE - 1, x + LIFE_SIZE - 1);
}
bool extraLifeCollision() {
int x = lifePtr -> x;
int y = lifePtr -> y + LIFE_SPEED;
brick *brick = getBrickAt(x, y);
if(y <= 0 || brick != NULL) {
return true;
}
paddle *paddlePtr = getPaddlePtr();
if(y <= paddlePtr -> y) {
int paddleX;
if(paddlePtr -> x < 0) {
paddleX = (paddlePtr -> x % -OLED_HEIGHT) + OLED_HEIGHT - 1;
}
else {
paddleX = paddlePtr -> x % OLED_HEIGHT;
}
if(x < paddleX) {
paddleX -= OLED_HEIGHT;
}
int collisionX = x - paddleX;
if(collisionX >= 0 && collisionX <= PADDLE_WIDTH) {
extraLife();
return true;
}
}
return false;
}
bool lifeAvailable() {
return extraLifeAvailable;
}
void setLifeAvailable(bool isLife) {
extraLifeAvailable = isLife;
}