You may had a working Pong last time. If so, you can start from there. Otherwise, download a decent Pong program. and start up Processing.
Study the program before going on. The
setup() method is
executed when the program is started, once.
draw() is executed 60 times a second. This can be
changed by calling
frameRate from inside
I’m sure your PONG game needs some polishing. Here are some suggestions.
Enabling the paddle
The paddle can be moved, but it does nothing.
Try to change the game so that the paddle does bounce the ball.
You can start by adding a test for the ball touching the paddle. This is
a little tricky because it involves testing both
Restarting the game
Once the paddle is working, modify the program so that a new
game is started if the ball touches the right end.
You can do this by setting
to their initial values when the ball runs off the right side of the table.
Add some randomness
It’s a bit boring that the game always starts with the ball moving
in the same direction.
You can use the
random() method to change this.
ballXSpeed = random(2.5, 6.0) ;
ballXSpeed to a randomly chosen value between
2.5 and 6.0.
What about a flashing sequence
Obviously, the game would be better if you could display a message like YOU LOSE when the ball falls off the right end. The best way to do this would be to use state machines, but those generally aren’t taught until upper-level computer science courses.
However, if you are really motivated, a clever use of
might do the trick.