Game Development Reference
In-Depth Information
private var CrosshairsGif:Class;
*/
Next, we define the constructor itself. Recall that this function sets gameWidth and gameHeight as
passed in by Main but doesn't do anything else. A bit later, we will use gameWidth and gameHeight
to calculate important values (i.e., where to place Enemy planes and Ship objects on the screen).
FlakCannon now waits for the Main class to call its functions. The first will be newGame() .
public function FlakCannon(gameWidth:int,gameHeight:int) {
this.gameWidth=gameWidth;
this.gameHeight=gameHeight;
}
Starting a new game
The newGame() function is one of the places where the FlakCannon class interfaces with the Main
class. If you recall from Part 1, an instance of a Game class (or a class extended from Game like
FlakCannon ) does nothing without receiving calls from the Main class. This allows Main to be in
control (i.e., take care of the boring stuff like showing title screens), and it also allows FlakCannon
to take care of the game logic (i.e., do the cool stuff like make Flak Cannon shells go boom!).
Here is the full code for the function:
override public function newGame():void {
level = 0 ;
score = 0;
ships = 3;
shots = 0;
extraShipCount=0;
isGameOver = false;
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_SCORE,"0"));
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_SHOTS,String(shots)));
}
The code in newGame() is pretty simple, with only a couple minor changes from Super Click. First,
we set the basic game variables to their initial values.
level = 0 ;
score = 0;
ships = 3;
shots = 0;
extraShipCount=0;
isGameOver = false;
Next, we set-up some events that we will use to tell Main some pertinent information about the
player progress in the game.
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_SCORE,"0"));
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_SHOTS,String(shots)));
Search WWH ::




Custom Search