CSCI 107 Solitaire Pong 2

Don’t get frustrated. This will be one last day to play with Pong. However, we will get to JavaScript one day and will be able to do similar stuff.

Starting out

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. The draw() is executed 60 times a second. This can be changed by calling frameRate from inside setup().

Processing references

Suggestions?

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 ballXPos and ballYPos.

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 ballXPos and ballYPos 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. For example:
    ballXSpeed = random(2.5, 6.0) ;
will set ballXSpeed to a randomly chosen value between 2.5 and 6.0.

Processing references

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 frameCount might do the trick.

Processing references