Game Development Reference
In-Depth Information
lastObstacleTime = 0;
lastExhaustTime = 0;
lastScoreEvent = 0;
obstacleDelay= 1000;
obstacleHeightMax= 10;
obstacleSpeed= 4;
playerStarted = false;
gameOver = false;
playerSprite.alpha = 1;
switchSystemState(STATE_SYSTEM_GAME_PLAY);
//key listeners
if (!keyListenersInit) {
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpListener);
keyListenersInit = true;
}
updateScoreBoard();
}
override public function newLevel():void {
stage.focus = this;
dispatchEvent(new CustomEventSound(CustomEventSound.PLAY_SOUND,
Main.SOUND_IN_GAME_MUSIC, true, 999, 8, 1));
addChild(playerSprite);
playerSprite.x = 300;
playerSprite.y = 200;
playerSprite.rotation = 90;
playerStarted = true;
lastObstacleUpgrade = getTimer();
lastObstacleTime = getTimer();
}
This code creates the game loop . The game loop uses the time-based step timer introduced in
Chapter 11. There are two values for the currentSystemState : SYSTEM_STATE_GAME_PLAY and
SYSTEM_STATE_PLAYER_EXPLODE .
override public function runGameTimeBased(paused:Boolean=false,
timeDifference:Number=1):void {
if (!paused) {
systemFunction(timeDifference);
}
}
public function switchSystemState(stateval:int):void {
lastSystemState = currentSystemState;
currentSystemState = stateval;
switch(stateval) {
case STATE_SYSTEM_GAME_PLAY:
systemFunction = systemGamePlay;
break;
Search WWH ::




Custom Search