Computer Graphics Final Write-up

The SpeedRacer game is made up of eight classes, and three nested classes for event handling in the 1.1 JDK:

Selected object message passing.

class SpeedRacer
This is the main class which extends Applet and creates three panels on the screen for drawing: the SkyCanvas, the DashCanvas, and the RoadCanvas.

class SkyCanvas
Above the horizon is the sky, which is currently drawn blue once, and is never repainted unless that part of the applet is exposed by another window.

class DashCanvas
This canvas shows the car's current speed (in the units of your choice), amount of damage sustained from hitting barriers (shown as a percentage bar), number of good guys (wearing red) and bad guys (wearing black and wielding guns) killed, total score, and time left.

class RoadCanvas
This is the workhorse class for the entire game, since it is responsible for drawing the bulk of the graphics and determining collisions between the car and Targets. First, it creates the Targets that will appear in the road. Following this, it creates the Ticker thread, that will periodically request that the game state be updated. See below for a description of the Ticker/RoadCanvas interaction.

class Target
Contains and is responsible for loading images for each item that you careen toward on the road. It can load two images and cycle between them at a given interval, if so desired. It also can move an image across the road at a given rate when its update() method is called. (This is how the people appear to "walk".) It also resets the location of the Target to the top of the screen at a random X position if it rolls off the bottom. One more image that it keeps track of: the dead image. This is the image that is displayed after the Target has been hit by the car.

class Car, class Line (not shown in diagram)
These are two simple "struct-only" classes that hold information about the Car's position and score, and the position of the lines in the road.

The ticker sleeps for a short amount of time (20 milliseconds), then calls the "tick()" method in its parent, then repeats the process. In this case the parent is the RoadCanvas, and it performs a variety of tasks in the tick() method, including:

Some improvements that could be made to the game are:

  1. There is no sound currently. I was hoping to make some cheesy sound effects, but my sound editor kept crashing. (I guess my home-made sounds were just that bad.)

  2. The images aren't drawn in the correct z-order. Since they tend to not collide with each other that often, this isn't usually seen. It does happen, though.

  3. The car should bounce and slow down if driven off the road.

  4. I wanted to have the "Game Over" text zoom in from the distance. I also want a "Speed Racer" intro screen of sorts.

  5. The lines tend to get bunched together as the game progresses. While I haven't tracked down this bug, I suspect it has to do with the car accelerating while some lines are closer to the bottom of the screen than others. A fix seems ugly, but not impossible.