players can hit the ball

This commit is contained in:
andrea
2026-03-14 21:53:39 +01:00
parent fcafc56012
commit adf2498344

View File

@@ -127,24 +127,55 @@ void move_ball() {
} }
else if (ball_x == 0) { else if (ball_x == 0) {
// p2 score, reset board // if p1 collision: reverse x, go left
ball_x= ball_reset_x; int hit= 0;
ball_y= ball_reset_y; for (int p1= p1_start; p1 < p1_start + bar_length; p1++) {
p2_score += 1; if (ball_y == p1) {
Serial.print("Player 2: "); ball_move_x= ball_move_x * -1;
Serial.println(p2_score); hit= 1;
Serial.print("Player 1: "); break;
Serial.println(p1_score); }
}
if (!hit) {
// else p2 score, reset board
ball_x= ball_reset_x;
ball_y= ball_reset_y;
p2_score += 1;
Serial.print("Player 2 score: ");
Serial.println(p2_score);
Serial.print("Player 1 score: ");
Serial.println(p1_score);
}
else {
ball_x += 1;
}
} }
else if (ball_x == 11) { else if (ball_x == 11) {
// p1 score, reset board int hit= 0;
ball_x= ball_reset_x; for (int p2= p2_start; p2 < p2_start + bar_length; p2++) {
ball_y= ball_reset_y; // if p2 collision: reverse x, go left
p1_score += 1; if (ball_y == p2) {
Serial.print("Player 2: "); ball_move_x= ball_move_x * -1;
Serial.println(p2_score); hit= 1;
Serial.print("Player 1: "); break;
Serial.println(p1_score); }
}
if (!hit) {
// else p1 score, reset board
ball_x= ball_reset_x;
ball_y= ball_reset_y;
p1_score += 1;
Serial.print("Player 2: ");
Serial.println(p2_score);
Serial.print("Player 1: ");
Serial.println(p1_score);
}
else {
ball_x -= 1;
}
} }
else if (ball_y == 0 || ball_y == 7) { else if (ball_y == 0 || ball_y == 7) {