Game Development Reference
In-Depth Information
seconds--;
if (seconds == min) {
stop();
dispatchEvent(new Event( TIME_IS_UP));
}
}
}
}
}
}
The class is takes in a single parameter representing the framesPerSecond . The user simply
needs to set a maximum and a minimum value for seconds and start and stop the timer as
necessary. It contains an attribute called countUp that starts set to false . The game loop must
call the update function of the timer for it to work. In the update cycle, the class uses the
frameCount variable to count up until it is equal to the passed in framesPerSecond . When it is, we
consider a second of game time to have passed. If so, the current value for seconds is either
increased or decreased.
If the seconds variable reaches maximum (counting up) or minimum (counting down) the
TIME_IS_SUP event constant is dispatched. The Game will listen for this event and (in our case) set
the gameOver variable in the DriveSheSaid class to true .
Creating the LookAheadPoint class
The LookAheadPoint class is used for collision detection between the player's car and all of the
tiles in the game. We will use three of these, placed at the front middle, left, and right of the car if
it is moving with a positive velocity. If it is moving with a negative velocity, we will place these at
the rear of the car. This class will extend Sprite because we want to be able to see these points
while coding and testing. This way, we can turn on a circle that will wrap around the point for
visual reference. This will allow us to visually see the points where the car will come into contact
with the game level tiles and will help to test out the collision detection.
This is the file location:
/source/classes/com/efg/framework/LookAheadPoint.as/
Here's the complete code for the class:
package com.efg.framework
{
import flash.display.*;
/**
* ...
* @author Jeff Fulton
*
*/
public class LookAheadPoint extends Sprite {
public var parentContainer:Sprite;
private var circle:Shape;
private var circleColor:Number;
public function LookAheadPoint(x:Number, y:Number, parentContainer:Sprite,
circleColor:Number=0xffff00) {
Search WWH ::




Custom Search