Game Development Reference
In-Depth Information
private function checkforEndLevel():void {
if (mineManager.mines.length == 0 && particleManager.particles.length < 25 ) {
dispatchEvent(new CustomEventSound(CustomEventSound.STOP_SOUND,
Main.SOUND_MUSIC_IN_GAME, true));
disposeAll();
playerStarted = false;
//erase player from screen
canvasBitmapData.copyPixels(backgroundBitmapData, new Rectangle(0,0,32,32),
player.point);
dispatchEvent(new Event(NEW_LEVEL));
}
}
When the
gameOver
variable is set to
true
, the
checkForEndGame
function will switch the
currentSystemState
to
STATE_SYSTEM_PLAYEREXPLODE
. While in the
STATE_SYSTEM_PLAYEREXPLODE
state, the
systemFunction
is set to the
systemPlayerExplode
function. This function will continue
to call the
update
and
render
functions on each frame tick until all of the particles that make up
the player's explosion have left the screen.
private function systemPlayerExplode(timeDifference:Number=0):void {
update(timeDifference);
render();
if (playerExplosionParticles.length == 0) {
playerExplodeComplete();
}
}
The
playerExplodeComplete
function is called by the
systemPlayerExplode
state function when
there are no more player explosion particles left.
Main
will change the framework system state
when it receives this event. Also, the
disposeAll
function is called. It will clean up all of the object
instances and get ready for a new game.
private function playerExplodeComplete():void {
dispatchEvent(new Event(GAME_OVER));
disposeAll();
}
Adding the update, autoShoot, render, and collision
functions
The
update
,
autoShoot
,
render
, and
collision
functions are very similar to ones you have seen
in previous games. We have also described most of the functionality previously in this chapter.
We will go over the highlights and any new and previously not mentioned subjects.
private function update(timeDifference:Number = 0):void {
//time based movement modifier calculation
var step:Number = (timeDifference / 1000)*timeBasedUpdateModifier;
//*** auto fire