User manual

002
if (ballX == 1 || ballX == 127) {
003
setup();
004
}
005
if (ballY == 1 || ballY == 63) {
006
collisionY = collisionY * -1;
007
}
008
if (abs(ballX - player1X) <=2 && abs(ballY - player1Y) < 9) {
009
collisionX = collisionX * -1;
010
level++;
011
}
012
if (abs(ballX - player2X) <=2 && abs(ballY - player2Y) < 9) {
013
collisionX = collisionX * -1;
014
level++;
015
}
016
ballX = ballX + collisionX;
017
ballY = ballY + collisionY;
018
}
As you can see, there are different queries regarding the ball position. A ball at x-
position 1 or 127 means that it was not successfully deflected and has travelled
out of the field off the left or right edge. In this case, the setup routine is called and
the game can start again from the beginning. A ball at the y-position 1 or 63,
means that the ball bounced off over the upper or lower edge by negating the
collisionY variable and thus reversing the direction of the ball movement. Both
queries
if (abs(ballX - player1X) <=2 && abs(ballY - player1Y) < 9)
determine whether the ball is reflected on a paddle. This is done by checking
whether the ball is close enough to the paddle and whether it hits the paddle. If
this is the case, the movement variable is reversed to x-direction and the level is
increased.
001
002