User manual
003
player1Y++;
004
}
005
if (player1Y > 55) {
006
player1Y--;
007
}
008
player1Y = (player1Y -1 + random(3));
009
if (player2Y < 7) {
010
player2Y++;
011
}
012
if (player2Y > 55) {
013
player2Y++;
014
}
015
player2Y = (player2Y -1 + random(3));
016
}
The movement of the player (paddle), however, is determined at random. But
whether the paddle travels too closely to the upper or lower edge will be checked
before that. An excursion upwards or downwards is generated by adding a random
number between -1 and 1. The function call random(3) generates random num-
bers between 0 and 2. This value range is shifted to the adequate value range
using "-1".
001
void controlBall() {
002
if(engine.joypad.isPressed(UP) && ballY > 2){
003
ballY = ballY - 1;
004
}
005
if(engine.joypad.isPressed(DOWN) && ballY < 61){
006
ballY = ballY + 1;
007
}
008
if(engine.joypad.isPressed(LEFT) && ballX > 13){
009
ballX = ballX - 1;
010
}