Java for Video Games

Homework 3
Pong Modification



Introduction

You'll work on this assignment in pairs.  Be sure to start early because this assignment will take much longer than the previous two combined.  You will be assigned a partner for this program.  You should communicate with your own partner for this assignment (you are also welcome but not encouraged to work alone).  We may assign partners for future assignments.

Pong is arguably the first video game.  Despite it's apparent simplicity, there exist challenges in pong that still exist in many modern video games.  In this assignment you'll experiment with Pong.  You'll add some enhancements that will make the game more interesting.

Requirements

Pong Alterations (more details to come on this part of the assignment)

How to

  1. Start a new project and import pong.jar which contains the code for the game.
  2. Import tipgame.jar the most recent version of the gaming package
  3. Run the program by running PongLoop.  You can run PongLoop either as an applet or an application.
  4. You'll notice a class in tipgame called YourSprite.java.  Modify this class to make a more interesting Sprite.  YourSprite must
    Consult the SpriteTest example on the Gaming Engine Website for examples of CAG and General Path.
  1. Now go to PongLoop.java where the ball is made.  You'll notice one line commented out that would make a new YourSprite object.  Uncomment this line (and optionally comment the line above it which is now redundant).
  2. Run the program.  You should see now YourSprite as the ball moving around.
  3. Open up ProjectileTracker.java.  Go to the advanceTime method that changes the position.  If you also change the velocity at every time step you'll be simulating gravity!  In the beginning of the method add in the line
    velocity.y+=49*time;
  4. Run the program.  Experiment with different values of gravity.
  5. Add a sound at each collision.  Optionally make the sound different when the ball hits different sprites.
    1. Add the following four lines to the import statements at the top of PongLoop.java.
      //the next three imports are necessary for sound
      import java.applet.*;
      import java.net.*;
      import javax.swing.*;
    2. Add the following instance variable/constant
      /**the clip that is played when the ball bounces*/
      AudioClip bounceClip;
      /**the file to load into the clip*/
      private static final URL CLIP_FILE=PongLoop.class.getResource("audio/DingLower.wav");
    3. Add the following method
      /**
       * initializes the sound clips
       */
      private void makeSoundClips()
      {
          bounceClip=JApplet.newAudioClip(CLIP_FILE);
      }
    4. Call the above method from the constructor in Pong.
    5. In the handleCollisions() method, add the line
      bounceClip.play();
      when the ball collides with anything.
  6. Add 2 other enhancements of your choice.  Try most simple suggestions before trying any advanced suggestions.
    Advanced suggestions include:
    1. Add splash screens.
    2. Keep score.
    3. Make an artificially intelligent opponent.
    4. Make more realistic collisions (advanced physics involved here).  Defitinitely forward me the source code if you figure this one out, especially if you do it with angular momentum.
    Simple suggestions include:
    1. Changing the text of the paddles.
    2. Making the ball spin.
    3. Making the ball change colors when it bounces.
    4. Make 2 balls.  The balls should also bounce off ecah other.
  7. Save your project by exporting a jar file and saving it to your account (include source in this jar file).
  8. Update your web page for this homework by posting your applet (information on this soon).