Game Development Reference
In-Depth Information
Even more simply, we could write it as follows:
If 100 >= 10000
This time, the statement is false, so no
Ship
would be awarded.
Besides this little detail, the rest of this function is self-explanatory.
private function checkBonusShips():void {
if ( (score-(extraShipCount*scoreNeededForExtraShip) >= scoreNeededForExtraShip) )
{
ships++;
extraShipCount++;
dispatchEvent( new CustomEventSound(
CustomEventSound.PLAY_SOUND,Main.SOUND_BONUS_SHIP,false,1,0,1));
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_SHIPS,String(ships)));
}
}
Rendering objects
The
render()
function called by
runGame()
to actually move the objects on the screen. For each
array of objects that either moves (
Shot
,
Enemy
, and
BonusPlane
) or animates (
Flak
and
Explosion
), we run through a separate
for:each
loop. We can use
for:each
here, because we
are not removing anything from the arrays, we are only calling the render function of each object.
private function render():void {
for each (tempShot in shotArray){
tempShot.render();
}
for each (tempFlak in flakArray){
tempFlak.render();
}
for each (tempEnemy in enemyArray){
tempEnemy.render();
}
for each (tempExplode in explodeArray){
tempExplode.render();
}
for each (tempBonusPlane in bonusPlaneArray){
tempBonusPlane.render();
}
}
Ending a level
The next to last function called by
runGame()
is
checkForEndOfLevel()
. This function looks to see
if the all the conditions exist to advance to player to the next level of the game. There are two
major variables that determine if the
level
has been completed: the length of the
enemyArray
array, and
incomingCount
.
incomingCount
is used to determine if the number of
Enemy
planes
created for this level is equal to the difficulty setting
numEnemies
. If so, we know we will not create
any more
Enemy
objects for this level. However, there could still be
Enemy
planes on the screen.
Since they are tracked in
enemyArray
, we look at the
length
property of that array to determine if
the there are any left on the screen.