Pong
CPS 004.1, 29 July 2003
Named after its distinctive sound, Pong is generally considered the first
popular computer game. It
was developed by Atari in 1972 and had only two instructions: deposit
quarter and avoid missing
the ball for high score. It was an incredible hit and marked the
beginning of the "arcade
revolution". A description of this first arcade game is available
here.
A pictorial history of the game can be found
here.
An example is available online
here.
Specifications
Your task is to write the classic arcade game Pong for a single player. In this variation, the player
must keep the ball bouncing around the applet without letting it hit the bottom wall by moving a
"paddle" along the bottom of the applet. If the ball hits the paddle it should bounce off the paddle
as if it were a wall and the player's score should be incremented; if it misses then it reappear in
random position and the player's score should be reset to 0.
You should complete the following basic requirements:
- Make a ball that is 20x20 pixels, with a random position (somewhere above the paddle) and
random velocity (initially pointed away from the paddle on the applet's bottom).
- Make a paddle that is 50x10 pixels, positioned in the center of the applet horizontally and 20
pixels from the applet's bottom vertically.
- Make bounce behaviors that causes the ball to bounce off the walls and the paddle.
- Make follow behaviors that causes the paddle's horizontal position to follow the mouse's
horizontal position, but in no way goes beyond the applet's boundaries. Its vertical position
should never change.
- Make a score in which one point is added each time it bounces successfully off of the paddle.
The score should be reset to zero each time the ball bounces off the bottom wall (i.e., each
time the paddle misses the ball).
- Make an applet class that creates a ball and a paddle and starts the game.
To be a true game there must be a high score, increasing challenge, and perhaps even more chances
for points. Once you have made the basic game, you must do at least three of the following to
distinguish your game from your classmates.
- Increasing speed. The ball's velocity should increase as the score increases. It should also be
reset each time the ball hits the bottom wall.
- Shrinking paddle. The paddle's width should decrease as the score increases. It should also be
reset each time the ball hits the bottom wall.
- High score. A second score should be added that keeps track of the maximum score reached
during the game.
- Random bounces. The ball should bounce off the paddle in a random direction (away from
the paddle) if the ball hits either end of the paddle (but not the center area).
- Multiple bouncing balls.
- Paddle velocity. Give the paddle a velocity that it imparts on the ball when they collide, i.e.,
when the paddle hits the ball when moving quickly, the ball bounces off the paddle with a
higher speed.
- Lives. The player loses a life when the ball bounces off the bottom wall; when the number of
lives reaches zero the game should stop.
- Scoring areas. Create some areas in the applet that can score bonus points if a ball hits them.
- Multiple paddles (one along each wall). All paddles should move in unison when the mouse
moves.
- Computer controlled paddle. An opponent paddle opposite the player's that moves on its
own to play pong. More credit will be given making it look more realistic, i.e., not simply
moving the correct spot immediately and waiting for the ball (and perhaps even missing the
ball once in a great while).
Advice
This program is a step up in size and complexity from the previous assignments, so it is more
important than ever to think about the algorithms you will need before you write any code. Even
more important though is that you code the program in small steps: do something well, then move
on. Small victories will be very important to your morale in this assignment. There are many ways
to approach this project, one way that we suggest is the following:
- Like your previous project, make a shape that falls --- call this your ball
- Give your ball random attributes and making it move in a random direction instead of
straight down
- Add to your behavior to make the ball bounce off the sides of the applet
- Add a paddle that follows the mouse
- Constrain the paddle's motion so that it ignores the y-component of the mouse's position
- Constrain the paddle's motion so that it stays within the applet
- Add to your behavior to make the ball bounce off the paddle
- Customize your game to distinguish it from your classmates
What to Submit
You have two days to complete this project; however, you must create a link to your applet from
your CPS 4 web page today so that we can monitor your progress. You will only
need to have one link on your page for the entire project, not each of the steps needed to complete
it. At the end of each day, you and your partner should transfer the entire project folder created by
Visual J++ to your respective public_html/cps4 folder in the acpub system.