This is the source code for the classic paddle game on the iPhone® platform. The game consists of a two paddles that bounce a square "ball" back and forth, with sound effects for
There are two versions included, Quartz2D and OpenGL. The game logic is the same for both versions, with a main loop driven by an NSTimer, an update function that calculates the ball's position and collision detection, and a render method that draws the current game state onto the screen.
User touch controls one paddle, while a very simple AI controls the opponent panel. A double tap on the screen pauses the game play, while a single tap resumes play.
The project layout is kept simple for readability. The entire game code is included in a single class, using C structs instead of classes for the points and sprites. Thus, the code is a mix of C, Objective-C, and Quartz/OpenGL.
Use this code to see how a simple game is implemented on the iPhone.