-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrick.ino
84 lines (75 loc) · 3.38 KB
/
Brick.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
void Brick() {
//Bounce off Bricks
// SerialUSB.print("Do Brick");
for (int8_t row = 0; row < ROWS; row++) {
// SerialUSB.println(" ");
// SerialUSB.print("Row "); SerialUSB.print(row);
for (int8_t column = 0; column < COLUMNS; column++) {
// SerialUSB.print(type_brick[row][column]);SerialUSB.print("|");
if (!isHit[row][column] ) {
// Manage brick and ball collision
if (type_brick[row][column] > 0) {
draw_brick(type_brick[row][column], BrickWidth * column, BrickHeight * row + Ytop);
if (balle.y <= (BrickHeight * (ROWS + 1) + Ytop)) {
if (metal==false) {
// Test vertical collision
if (balle.moveY > 0) {
if (balle.y <= (BrickHeight * (row+1) + Ytop - balle.BSize) && (balle.y >= (BrickHeight * row + Ytop - balle.BSize) && (balle.x > (BrickWidth * column - 0.5*balle.BSize)) && (balle.x < (BrickWidth * (column + 1) - 0.5 *balle.BSize)))) Y_bounce(row,column);
} else if (balle.y <= (BrickHeight * (row + 1) + Ytop ) && balle.y >= (BrickHeight * row + Ytop ) && (balle.x > (BrickWidth * column - 0.5*balle.BSize)) && (balle.x < (BrickWidth * (column + 1) - 0.5 *balle.BSize))) Y_bounce(row,column);
} // If ball is metal, don't bounce: the ball go through all !!
/* //Test hoizontal collision
else if (balle.x <= (BrickWidth * (column + 1) - balle.moveX - 0.5*balle.BSize+1)) {
if (balle.moveX < 0) X_bounce(row,column);
} else if (balle.x >= (BrickWidth * column - 0.5*balle.BSize - balle.moveX -1)) {
if (balle.moveX > 0) X_bounce(row,column);
} // -- End horizontal collision */
} // -- End test Y (Ball in Brick zone)
} // -- End brique > 0
} // -- End test isHit
} // -- End for Column
} // --End for Row
} // -- End Brick()
// Draw the defined brick
void draw_brick(int8_t BrickType, int8_t XB, int8_t YB) {
if (BrickType > 10) BrickType = defaultBonusBrick;
if (BrickType > 0) gb.display.drawImage(XB, YB, BR[BrickType - 1]);
}
void Collision(int8_t r,int8_t c ) {
//If a collison has occured
if (type_brick[r][c] > 1) {
brickCount++;
score = score + NbPointsBrick;
SerialUSB.print("Collision => type_brick[r][c]:");
SerialUSB.println(type_brick[r][c]);
// Manage bonus / malus add
if (type_brick[r][c] == 11 || type_brick[r][c] == 12 || type_brick[r][c] == 14 || type_brick[r][c] == 20 || type_brick[r][c] == 21 ) {
gb.sound.fx(SBonus);
Add_bonus(type_brick[r][c],BrickWidth * c,((r+1)*BrickHeight + Ytop));
} else if (type_brick[r][c] == 13 || type_brick[r][c] == 17 || type_brick[r][c] == 18 || type_brick[r][c] == 19 ) {
gb.sound.fx(SLostlife);
Add_bonus(18,BrickWidth * c,((r+1)*BrickHeight + Ytop));
} // end Switch
isHit[r][c] = true;
}
}
void Y_bounce(int8_t r,int8_t c) {
//Only bounce once each ball move
Collision(r,c);
if (!bounced) {
balle.moveY = - balle.moveY + random(-1, 1) / 6;
Bounce();
}
}
void X_bounce(int8_t r,int8_t c) {
//Only bounce once each ball move
Collision(r,c);
if (!bounced) {
balle.moveX = - balle.moveX + random(-1, 1) / 6;
Bounce();
}
}
void Bounce() {
delay(5);
bounced = true;
gb.sound.tone(261, 200);
}