Game Development Reference
In-Depth Information
case STATE_SYSTEM_PLAYER_EXPLODE :
systemFunction = systemPlayerExplode;
break;
}
}
private function systemGamePlay(timeDifference:Number=0):void {
if (playerStarted) {
checkInput();
}
update(timeDifference);
checkCollisions();
render();
updateScoreBoard();
checkforEndGame();
}
private function systemPlayerExplode(timeDifference:Number=0):void {
playerSprite.alpha -=.005;
if (playerSprite.alpha <= 0) {
playerExplodeComplete();
}
}
public function checkforEndGame():void {
if (gameOver ) {
playerStarted = false;
switchSystemState(STATE_SYSTEM_PLAYER_EXPLODE);
dispatchEvent(new CustomEventSound(CustomEventSound.PLAY_SOUND,
Main.SOUND_EXPLODE, false, 1, 8, 1));
}
}
private function playerExplodeComplete():void {
dispatchEvent(new Event(GAME_OVER) );
lastScore = score;
trace("lastScore=" + lastScore);
disposeAll();
}
This code allows user input. The only user input we need in Tunnel Panic is the space bar. When
it is pressed, we decrease the y value of the playerSprite (moving it up the screen).
private function checkInput():void {
if (keyPressList[32]) {
playerSprite.y -= playerSpeed;
}
}
private function keyDownListener(e:KeyboardEvent):void {
keyPressList[e.keyCode] = true;
}
private function keyUpListener(e:KeyboardEvent):void {
keyPressList[e.keyCode] = false;
}
Search WWH ::




Custom Search