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)
- Altering Sprites - make a more interesting ball.
- Altering Trackers - Pong is more fun with gravity, right?
- Add some sound - almost every game is better with sound
- Add some enhancements
How to
- Start a new project and import pong.jar
which contains the
code for the game.
- Import tipgame.jar
the most recent version of the gaming package
- Run the program by running PongLoop. You can run PongLoop
either as an applet or an application.
- You'll notice a class in tipgame called YourSprite.java.
Modify
this class to make a more interesting Sprite. YourSprite must
- be original
- use CAG (Constructive Area Geometry) or a
GeneralPath
- have color
Consult
the SpriteTest example on the Gaming Engine Website for
examples of CAG and General Path.
- 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).
- Run the program. You should see now YourSprite as the ball
moving
around.
- 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;
- Run the program. Experiment with different values of
gravity.
- Add a sound at each collision. Optionally make the sound
different when the ball hits different sprites.
- 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.*;
- 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");
- Add the following method
/**
* initializes the sound clips
*/
private void makeSoundClips()
{
bounceClip=JApplet.newAudioClip(CLIP_FILE);
}
- Call the above method from the
constructor in Pong.
- In the
handleCollisions() method, add the line
bounceClip.play();
when the ball collides with anything.
- Add 2 other enhancements of your choice. Try most simple
suggestions before trying any advanced suggestions.
Advanced suggestions include:
- Add splash screens.
- Keep score.
- Make an artificially intelligent opponent.
- 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:
- Changing the text of the paddles.
- Making the ball spin.
- Making the ball change colors when it bounces.
- Make 2 balls. The balls should also bounce off ecah other.
- Save your project by exporting a jar file and saving it to your
account
(include source in this jar file).
- Update your web page for this homework by posting your applet
(information
on this soon).