Homework 5
22C:80 Programming for Informatics
Due Wednesday, February 25, 2009
14 points

Make a working pong game by completing the updateGameState in the Pong game code. Make sure to to read the comments in the pong game code for some details.

Note (2/23/09): if the GUI "Up", "Down", "Quit" buttons don't work reasonably well on your system, you may do your work in the"no-GUI" version here. The paddle doesn't move but at least it should work well on any machine and you should be able to get all the bouncing code working correctly.

Completing this project is in many ways just a generalization of HW4's scrolling program. Scrolling was one dimensional - you had to detect when the word reached the left and/or right ends of the window. Igoring the paddle (which you should until you get everything else working), pong is very similar exept that it's two dimensional - you simply need to detect when the "ball" (really, a small square) reaches the left, right, top, or bottom of the game area.

You don't need to understand the main game code at all. Ignore the graphical interface buttons, the drawing of the ball and paddle, etc. My code handles all that. You simply need to do one thing. At each "frame" of the game, you must compute a new position and movement direction for the ball. You will do this in the updateGameState function. That function takes 11 arguments, which contain all the information you need to determine the ball's next position. The arguments are:

You'll compute four new values, perhaps saving them in variables called newBallX, newBallY, newBallXDir, and newBallYDir and then "send" them to the game in the last line of updateGameState (again, see the provided/sample code)

NOTE: If you get a strange error in JES when trying to run "playPong" again after you've already run it at least once, click the "Load Program" button and try "playPong" again. I don't know why this happens but re-loading the code seems to get rid of the problem.