Game Development Reference
In-Depth Information
6.
The
nextX
and
nextY
values are changed to add
xMove
and
yMove
respectively and are
checked against the minimum and maximum x and y values. There is no warping to
the opposite side of the screen in this game (unlike Atari Asteroids), so the player ship
object is stopped if it tries to go outside these boundaries.
nextX+=yMove;
nextY+=xMove;
if (nextY > xMax) {
nextX = xMax;
}else if (nextX < +xMin) {
nextX = xMin;
}
if (nextY > yMax) {
nextY = yMax;
}else if (nextY < yMin) {
nextY = yMin;
}
7.
Finally, the new frame of animation (a rotated
BitmapData
instance) from the
animationList
array is selected based on the new degrees for the object. If the degree
number is less than
0
, we need to offset it by
359
, so it will represent the appropriate
array index for the animated frame.
frame = degrees;
if (degrees < 0) {
frame = 359+degrees;
}
bitmapData=animationList[frame];
And this is the third function in
BlitArrayPlayerFollowMouse
:
public function createPlayerShip(spriteGlowFilter:GlowFilter):void
This function will draw the ship as a vector shape and then use the BlitArrayAsset class to create
a 360-degree rotation of the ship as 32
32 BitmapData objects.
Here is the code that creates this array:
shipBitmapData.draw(drawingCanvas);
shipBitmapData.applyFilter(shipBitmapData, shipBitmapData.rect, new Point(0,0),
spriteGlowFilter);
animationList=tempBlitArrayAsset.createRotationBlitArrayFromBD(shipBitmapData, 1,90);
Once the ship has been drawn into the drawingCanvas, we use the BitmapData.draw method to
copy it to the shipBitmapData. We will examine this in the section called “Adding the Blaster
Mines game init functions.”
Here is the full source code for this class:
package com.efg.games.blastermines
{
import com.efg.framework.BasicBlitArrayObject;
import com.efg.framework.BlitArrayAsset;
import flash.display.BitmapData;