Game Development Reference
In-Depth Information
So that is all there is to the
Shot
class. However, we still need to talk about
Enemy
,
Ship
, and
BonusPlane
. Luckily,
BonusPlane
is nearly identical to
Shot
, so we will discuss that one next.
Enemy
and
Ship
also have some major similarities to
Shot
.
You may be thinking that if these classes are so close in structure, why didn't we create a class
and inherit from it? Honestly, the answer is just for clarity. You could easily take the common
elements of all these classes and create a base class for them that all of these objects would
instantiate from. We will leave this to you so you can create a more complex object model that fits
your particular style.
BonusPlane
We will use the code from
Shot
to create the code for the
BonusPlane
. The code changes to
support
BonusPlane
are very few. The
BonusPlane
always flies across the screen from left to right.
The only real difference then is the
bonusValue
instance variable (plus, obviously, the Flex
embed). The
bonusValue
variable is the number of extra shots the player earns by shooting down
the
BonusPlane
. We need to create an instance variable named
bonusValue
and pass in that value
to the constructor.
package com.efg.games.flakcannon
{
import flash.display.Shape;
import flash.display.Sprite
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Point;
public class BonusPlane extends Sprite
{
public var imageBitmapData:BitmapData;
public var image:Bitmap;
private var startLocation:Point;
private var endLocation:Point;
private var nextLocation:Point;
private var xunits:Number;
private var yunits:Number;
private var speed:Number = 5;
private var moves:int = 0;
public var bonusValue:int = 0;
public var finished:Boolean;
/*
[Embed(source = "assets/flakassets.swf", symbol="PlaneBonusGif")]
private var PlaneBonusGif:Class;
*/
public function BonusPlane(startX:Number, startY:Number, endX:Number, endY:Number,
speed:Number, bonusValue:int) {
startLocation = new Point(startX,startY);
endLocation = new Point(endX,endY);
nextLocation = new Point(0,0);
this.speed=speed;
this.bonusValue=bonusValue;
init();
}