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 by= _ball.get_y();
|
||||
|
||||
if (bx <= 0) {
|
||||
if (!this -> _check_pad_ball_collision(_p1)) {
|
||||
// pad is 1 pixel far from the edge, so i need to calc this delta
|
||||
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.increase_score();
|
||||
Serial.println("Player 2 Scores");
|
||||
@@ -38,13 +44,14 @@ void Engine::run() {
|
||||
_event= P2SCORE;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
_ball.bounce_on_pad();
|
||||
_event= P2_COLLISION;
|
||||
}
|
||||
}
|
||||
else if (bx >= MATRIX_WIDTH-1) {
|
||||
if (!this -> _check_pad_ball_collision(_p2)) {
|
||||
else if (bx >= MATRIX_WIDTH-2) {
|
||||
// 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.increase_score();
|
||||
Serial.println("Player 1 Scores");
|
||||
@@ -52,10 +59,6 @@ void Engine::run() {
|
||||
_event= P1SCORE;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
_ball.bounce_on_pad();
|
||||
_event= P1_COLLISION;
|
||||
}
|
||||
}
|
||||
|
||||
if (by == 0 || by == MATRIX_HEIGHT-1) {
|
||||
|
||||
Reference in New Issue
Block a user