Game Development Reference
In-Depth Information
so
image
still exists. Also, we need
currentImageIndex
, which holds the index of the images array
that we are current showing. We also need a
finished
Boolean, so
FlakCannon
can tell when the
animation is complete and can start the process to remove it from the screen.
frameCounter
is
used to define the number of frames that have passed since we have changed images. We use
this in conjunction with
frameDelay
to define the length of the animation. Finally, we have another
new variable named
hits
, it's a counter that we increment each time a plane is destroyed by this
Flak
explosion. Keeping track of
hits
allows us to give the player bonus points for destroying
more than one plane with a
Flak
explosion. After these new variables, we have to embed the Flak
explosion frames for Flex.
public var images:Array;
public var image:Bitmap;
public var currentImageIndex:int = -1;
public var finished:Boolean;
private var frameCounter:int = 0;
private var frameDelay:int = 2;
public var hits:int;
/*
//**Flex Framework Only
[Embed(source = "assets/flakassets.swf", symbol="Exp1Gif")]
private var Exp1Gif:Class;
[Embed(source = "assets/flakassets.swf", symbol="Exp2Gif")]
private var Exp2Gif:Class;
[Embed(source = "assets/flakassets.swf", symbol="Exp3Gif")]
private var Exp3Gif:Class;
[Embed(source = "assets/flakassets.swf", symbol="Exp4Gif")]
private var Exp4Gif:Class;
[Embed(source = "assets/flakassets.swf", symbol="Exp5Gif")]
private var Exp5Gif:Class;
[Embed(source = "assets/flakassets.swf", symbol="Exp6Gif")]
private var Exp6Gif:Class;
[Embed(source = "assets/flakassets.swf", symbol="Exp7Gif")]
private var Exp7Gif:Class;
*/
Since we do not need to move
Flak
, the constructor simply sets
hits
to 0 and calls
init()
.
hits
is a simple counter that we will use for scoring. Since a
Flak
explosion does not disappear when
it hits an
Enemy
, it can effectively destroy many planes. Hits will be used to keep track of the
number of
Enemy
planes that this
Flak
explosion has destroyed. We will give the player a bonus
for hitting multiple
Enemy
objects with one
Flak
object.
public function Flak() {
hits = 0;
init();
}
A lot of the new interesting code for
Flack
lives in
init()
. We are going to create
image
as a
holder for the current
Bitmap
and add it to the sprite. Then, we will fill the
images
array with all the