Game Development Reference
In-Depth Information
case STATE_SYSTEM_GAME_PLAY:
systemFunction = systemGamePlay;
break;
case STATE_SYSTEM_PLAYER_EXPLODE :
systemFunction = systemPlayerExplode;
break;
}
}
The
systemGamePlay
function makes use of the
timeDifference
variable by passing it into the
update
function.
private function systemGamePlay(timeDifference:Number=0):void {
trace("in game play");
update(timeDifference);
checkCollisions();
render();
updateScoreBoard();
checkforEndLevel();
checkforEndGame();
}
The
checkForEndGame
function is unique to this game. When the player runs out of shields, the
game is over. The
checkCollisions
function will set the
gameOver
Boolean to
true
when the
shield
variable is less than 0. We have a special explode function for the player that displays 300
particles. It reuses the projectile
BitmapData
for the look of the particles. The internal game state
machine is set to run in the
STATE_SYSYTEM_PLAYEREXPLODE
state rather than the normal
STATE_SYSTEM_GAMEPLAY
state when the
player
is in the process of exploding.
private function checkforEndGame():void {
if (gameOver ) {
dispatchEvent(new CustomEventSound(CustomEventSound.STOP_SOUND,
Main.SOUND_MUSIC_IN_GAME, true));
dispatchEvent(new CustomEventSound(CustomEventSound.PLAY_SOUND,
Main.SOUND_PLAYER_EXPLODE, false, 1, 8, 1));
canvasBitmapData.copyPixels(backgroundBitmapData, new Rectangle(0,0,32,32),
player.point);
createPlayerExplode(player.x + 16, player.y + 16, 300);
playerStarted = falset
switchSystemState(STATE_SYSTEM_PLAYER_EXPLODE);
}
}
The checkForEndLevel function decides if the player is ready to proceed to the next game level.
The level ends when all of the mines have been destroyed. We don't want the level to end too
abruptly, so we wait until there are only 24 particles left on the screen and then start the new
level. The player is erased from the screen by copying the background under the player back on
top of its current location.