fix ball bouncing on pad behavior
now the ball bounces on pad when hit the pad, not when it reaches the edge of the "screen"
This commit is contained in:
@@ -29,8 +29,14 @@ void Engine::run() {
|
|||||||
uint8_t bx= _ball.get_x();
|
uint8_t bx= _ball.get_x();
|
||||||
uint8_t by= _ball.get_y();
|
uint8_t by= _ball.get_y();
|
||||||
|
|
||||||
if (bx <= 0) {
|
// pad is 1 pixel far from the edge, so i need to calc this delta
|
||||||
if (!this -> _check_pad_ball_collision(_p1)) {
|
if (bx <= 1) {
|
||||||
|
// score the point only if ball reached the edge
|
||||||
|
if (this -> _check_pad_ball_collision(_p1) && bx == 1) {
|
||||||
|
_ball.bounce_on_pad();
|
||||||
|
_event= P2_COLLISION;
|
||||||
|
}
|
||||||
|
else if (bx <= 0) {
|
||||||
// p2 scores
|
// p2 scores
|
||||||
_p2.increase_score();
|
_p2.increase_score();
|
||||||
Serial.println("Player 2 Scores");
|
Serial.println("Player 2 Scores");
|
||||||
@@ -38,13 +44,14 @@ void Engine::run() {
|
|||||||
_event= P2SCORE;
|
_event= P2SCORE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
_ball.bounce_on_pad();
|
|
||||||
_event= P2_COLLISION;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (bx >= MATRIX_WIDTH-1) {
|
else if (bx >= MATRIX_WIDTH-2) {
|
||||||
if (!this -> _check_pad_ball_collision(_p2)) {
|
// score the point only if ball reached the edge
|
||||||
|
if (this -> _check_pad_ball_collision(_p2) && bx == MATRIX_WIDTH-2) {
|
||||||
|
_ball.bounce_on_pad();
|
||||||
|
_event= P1_COLLISION;
|
||||||
|
}
|
||||||
|
else if (bx >= MATRIX_WIDTH-1) {
|
||||||
// p1 scores
|
// p1 scores
|
||||||
_p1.increase_score();
|
_p1.increase_score();
|
||||||
Serial.println("Player 1 Scores");
|
Serial.println("Player 1 Scores");
|
||||||
@@ -52,10 +59,6 @@ void Engine::run() {
|
|||||||
_event= P1SCORE;
|
_event= P1SCORE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
_ball.bounce_on_pad();
|
|
||||||
_event= P1_COLLISION;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (by == 0 || by == MATRIX_HEIGHT-1) {
|
if (by == 0 || by == MATRIX_HEIGHT-1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user