Game Development Reference
In-Depth Information
import flash.geom.Point;
We need to know the location of the mouse pointer on the screen so we will know to what point
we need to fire a shot. ui.Mouse will give us that information.
import flash.ui.Mouse;
Finally, we import the classes we will need from the game framework and begin the FlakCannon
class definition.
import com.efg.framework.Game;
import com.efg.framework.CustomEventLevelScreenUpdate;
import com.efg.framework.CustomEventScoreBoardUpdate;
import com.efg.framework.CustomEventSound;
public class FlakCannon extends com.efg.framework.Game {
Setting the FlakCannon.as properties and constructor
Now that we have gotten the imports out of the way, it is time to get into some of the actual game
code. First, we must define the necessary variables in the properties section of the class. Most of
these properties will be new for every game. The first two properties, game Width and gameHeight ,
will be used to store the width and height of the screen passed to FlakCannon by Main .
//constructor
private var gameWidth:int;
private var gameHeight:int;
Next, we will define some variables that we will use to track properties specific to Flak Cannon.
The score will track the player's score. level is the game level that the player has currently
reached. This will be used to create the difficulty settings. The ships variables tracks how many
ships that player currently has (not necessarily how many are on the screen). shots tracks the
number of shots the player has left to fire at the Enemy planes. We will report most of these back
to ScoreBoard using a CustomEventScoreBoardUpdate event. isGameOver is simply a setting to tell
FlakCannon that game has finished, while extraCount is a running total the number of extra ships
the player has earned that we will use to calculate when and if they will earn an extra Ship .
//NewGame
private var score:int;
private var level:int;
private var ships:int;
private var shots:int;
private var isGameOver:Boolean = false;
The next variable is used to count how many extra ships the player has received by reaching the
value in the scoreNeededForExtraShip variable. Since the player rarely achieves a score that is
exactly the value of scoreNeededForExtraShip, we need to store how many extras the player has
received so we don't award extra ships unnecessarily.
private var extraShipCount:int = 0;
Now, we will create arrays and variables to hold the objects we will create in the game. Explosion
objects are held in explodeArray , Shot objects in shotArray , Ship objects in shipArray , Flak
explosions in flakArray , Enemy planes in enemyArray , and BonusPlane objects in
bonusPlaneArray . The player will control the Bitmap held in the crosshairs variable.
Search WWH ::




Custom Search