Game Development Reference
In-Depth Information
override public function newGame():void {
clicks = 0;
gameOver = false;
stage.addEventListener(MouseEvent.
MOUSE_DOWN, onMouseDownEvent);
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,
Main.SCORE_BOARD_CLICKS,String(clicks)));
}
override public function newLevel():void {
dispatchEvent(new CustomEventLevelScreenUpdate
(CustomEventLevelScreenUpdate.UPDATE_TEXT,
String(gameLevel)));
}
override public function runGame():void {
if (clicks >= 10) {
gameOver = true;
}
checkforEndGame();
}
public function onMouseDownEvent(e:MouseEvent):void {
clicks++;
dispatchEvent(new CustomEventScoreBoardUpdate
(CustomEventScoreBoardUpdate.UPDATE_TEXT,
Main.SCORE_BOARD_CLICKS,String(clicks)));
trace("mouse click number:" + clicks);
}
private function checkforEndGame():void {
if (gameOver) {
dispatchEvent(new Event(GAME_OVER));
}
}
}
}
What we are doing in this class
This will be one of the most simple games you will ever create. When the user clicks the mouse
button, we set up a MOUSE_DOWN event listener to increase the clicks variable and dispatch a
CustomEventScoreBoardUpdate event to Main to update the scoreBoard . The runGame function is
called on each frame tick. If the clicks variable is equal to 10 , the gameOver variable is set to
true . The runGame function also calls the checkForEndGame function on each frame tick. If the
gameOver variable is set to true , then the GAME_OVER event is dispatched to Main.as .
Search WWH ::




Custom Search