Game Development Reference
In-Depth Information
return(remove);
}
}
}
Designing the BasicBlitArrayProjectile class
The BasicBlitArrayProjectile class is also a subclass of BasicBlitArrayObject . It is used for
the projectile missiles that the player ship will fire during our game. This class will be added to
game framework package and is located in com.efg.famework .
There are no additional public attributes for this class, but here are the public functions :
The constructor is identical to the BasicBlitArrayParticle version.
public function update(xAdjust:Number, yAdjust:Number,timeBasedModifier:
Number=1 ):Boolean {
The update function accepts in xAdjust and yAdjust values. These are used to modify the speed
of the projectile (if needed) and add the player's speed to the projectiles. This way, you never
have projectiles that are slower than the object firing them. The nextX and nextY values will be
multiplied by the timeBasedModifier . This value is used to keep the distance that objects move in
a single second constant no matter what frame rate the game SWF is playing at. This was
discussed in the section called “Creating the time-based step timer.”
The algorithm looks like this:
nextx+=(dx*(speed+Math.abs(xAdjust))) *timeBasedModifier;
nexty+=(dy*(speed+Math.abs(yAdjust))) *timeBasedModifier;
To determine whether or not to remove the projectile from the screen, the new nextX and nextY
attributes are matched against maximum and minimum x and y values for the object; true is
passed back to the caller if the object is outside these boundaries.
if (nextX > xMax || nextX < xMin || nextY > yMax || nextY < yMin) {
remove = true;
}
return(remove);
Here is the full source for this class:
package com.efg.framework
{
import com.efg.framework.BasicBlitArrayObject;
import com.efg.framework.BasicBiltArrayProjectile;
public class BasicBiltArrayProjectile extends BasicBlitArrayObject{
public function BasicBiltArrayProjectile(xMin:int,xMax:int, yMin:int, yMax:int ) {
super(xMin, xMax, yMin, yMax);
}
public function update(xAdjust:Number, yAdjust:Number,step:Number=1 ):Boolean {
//x adjust and y adjust change speed of projectile.
//in this case they are used to ensure that sprojetciles are as fast
Search WWH ::




Custom Search