CPE 471 Final Project
by: Brae Irwin

Overview

This program is my implementation of the classic Pong game, only expanded to the third dimension. Because this program is written in C++/OpenGL/GLUT, it is completely cross-platform compatible between Mac OS X and Windows. Most of my development took place in Xcode, with the binaries compiled in Xcode and Visual Studio .NET 2003. My Pong 3D program is available here:

Download

Pong 3D for Mac OS X (.tgz, 20kb)
Pong 3D for Windows (.zip, 92kb)

Installation

Mac Users: Just double-click the app!

Windows Users (sigh... windows): If you haven't done so already, install GLUT. To do this, unzip the glut.zip download and place the glut32.dll file into C:\Windows\system32. After that, unzip the Pong3DWin.zip download and double-click the exe file. Leave the bmp in the same directory as the exe, please!

 

     General Rules

  • Left-click ball to start playing
  • 3 wins per level
  • 5 balls to start
  • Move paddle when hitting ball for curve
  • Extra ball at levels 5, 10, 15, 20, etc.

     Controls

  • Right-Click or P key = PAUSE
  • C key = CURVING ON/OFF
  • R key = RESTART VOLLEY
  • V key = ORTHO/PERSPECTIVE (just for fun)
  • '+' key = LEVEL UP
  • '–' key = LEVEL DOWN
  • 5 key = NORMAL VIEW
  • 2 key = BOTTOM VIEW
  • 8 key = TOP VIEW
  • 4 key = LEFT VIEW
  • 6 key = RIGHT VIEW
  • Q key = QUIT (but who would do that? ;-)

Motivation

Although I am too young to have experienced the original release of Pong in 1972, I have always enjoyed playing the numerous variants that have been released since then. This seemed like an appropriate project for me to undertake that would keep me interested and encouraged. Also, for such a simple game concept, there are plenty of modifications and enhancements that can be implemented to create a more interesting gameplay experience; this gives the opportunity for welcome expansion possibilities.

Window Elements

The window begins with both paddles and the ball centered in the playing area. The crosshairs on the paddles serve no purpose other than to show you where the center of your paddle is. Directly beneath the ball is the ball's shadow. This shadow is to help you better see where the ball is located depth-wise. As the ball moves higher, the shadow will begin to fade; likewise, when it moves lower, the shadow begins to darken.


Initial Screen

At the top left of the window is the number of balls you have remaining, in addition to the current one in play. At the top right is the level progress bar. This bar indicates how much of the current level has been completed. When the bar is full, you will move on to the next level. At the lower left is the current level indicator. This area shows the level you are currently on.


Level 7, 2 balls remaining, 2/3 finished with the level

Gameplay

Pong's goal is simple: hit the ball past the opponent's paddle. The playing area consists of a 3D rectangular open box that extends into the screen. At the near end is your paddle and at the far is the computer opponent's. You control your paddle by moving the mouse around the window. The paddle's movement is limited to the extremities of the near plane of the playing area. Upon starting the game, the ball is stationary at the center of the screen. A left-click of the paddle on the ball commences play. Each game begins at Level 1 with 5 balls available to you, as shown in the top left corner of the window.

The computer opponent will move to rebound the ball back toward you. The effectiveness of the opponent increases as the levels progress. At Level 1, the opponent is easily overtaken. Each level is completed by successfully hitting the ball past the opponent 3 times. At the beginning of each level, the opponent's paddle is able to move faster and the initial ball velocity is also higher than the previous levels. With each hit of the ball on your paddle, the ball's velocity and amount of curve is increased slightly.

The "twist" in the name of the game refers to the ball's ability to curve - with the right twist of the wrist you can send the ball corkscrewing towards your opponent. To curve the ball, move the paddle while the ball is in contact with it. The ball will then bounce off the paddle and begin curving in the opposite direction that the paddle was moving. Each time the ball hits a wall while curving, it loses 60% of its curve. This simulates more realistic rebounds when coming in contact with a wall. However, when the opponent hits the ball back, it loses all of its curve. This ensures that the opponent always hits the ball in a linear trajectory and eases gameplay, especially at high velocity levels.

If the opponent manages to hit the ball past you, you lose one ball you have remaining. When all of these are gone, the screen fades into and out of black and gameplay resumes at Level 1 with 5 balls, as normal. Upon completion of a level that is a multiple of 5 (i.e. 5, 10, 15, 20, etc), another ball becomes available to you.

Graphics

The shading you see on the walls is created by a point light with distance attenuation enabled (the inverse square term). A separate light shades the ball and the remaining balls indicator at the top. The progress bar is lit with both lights, producing a neat lighting effect along its length. The level indicator at the bottom of the screen uses tally marks. This was a design decision that originally stemmed from the difficulties of displaying text in an OpenGL/GLUT window.

OpenGL does not provide a straightforward way to display text, at least that I could find. For this reason, I decided to eliminate a score counter from my game. The word "LEVEL: " is texture mapped at the lower left. I chose to display tally marks as opposed to texture mapping each number 0 through 9 and then creating a routine to display the correct digits based on an integer value in the code. I have never seen tally marks used like this in a game, so I thought it would be a unique touch and more interesting considering I chose to not implement a score of any kind.

I enabled blending to allow the paddles to be semi-transparent so that the paddle does not block a portion of your view of the playing area. Also, each time the ball hits a paddle, there is a brief flash to white and fade back to color on the paddle's surface. Your paddle is colored green while the opponent's is red. Although normally blue, the ball changes color similarly when you win or lose. A win for you will turn the ball green and halt its movement at the far plane. A loss will turn it red at the near plane. This way it is easy to visually see when a volley is over.

The ball's movement is defined by spherical coordinates (2 angles) which are then converted to cartesian coordinates to move the ball. When a ball hits a wall or paddle, its angle of reflection is equal to its angle of incidence. When curving, the ball's angles change accordingly as it moves through air toward the opponent. The game is programmed so that the opponent is unable to curve the ball towards you. This is mostly a decision of difficulty. I opted to increase the difficulty of play by increasing the opponents velocity of movement (to better keep up with the ball), increasing the velocity of the ball, and increasing the amount of curve. As stated before, the ball velocity and curve increase incrementally each time you hit the ball.

References

A simple site for spherical-cartesian conversion: Spherical Coordinates

Some OpenGL materials: OpenGL/VRML Materials

My source for lighting attenuation, but they have a lot on lighting in general: OpenGL Programming Guide - Chapter 5, Lighting

     

Links

My website: BraeIrwin.com

Professor Zoe Wood's CSC471 - Introduction to Computer Graphics