Game Development Reference
In-Depth Information
confines of the play field. The starting y value ( startY ) is simply -32, which means the entirety of
the height of the Enemy will start off screen. The ending y value (endY ) is the height of the screen.
} else {
startX = Math.floor(Math.random() * (gameWidth-32));
startY = -32;
endY = gameHeight;
dir = Enemy.DIR_DOWN;
}
Next, we create an instance of Enemy using the values we just calculated, add it to the display list
with addChild() , and push it into our array of Enemy planes, enemyArray . We also update
incomingCount so we can test it later to see if the level has been completed. Finally, we set the
enemyFrameCounter to 0 so it can start counting again and be tested the next time
checkEnemies() is called.
tempEnemy = new Enemy(startX,startY,endY,enemySpeed,dir);
this.addChild(tempEnemy);
enemyArray.push(tempEnemy);
incomingCount++;
}
enemyFrameCounter = 0;
}
}
Checking for a bonus plane
A bonus plane, shown in Figure 5-7, arrives at a regular interval to give the player a chance to
earn more shots for the flak cannon.
Figure 5-7. A bonus plane enters the screen
Here are the aspects of BonusPlane that make it different from Enemy :
The BonusPlane always arrives flying from the left to the right.
Search WWH ::




Custom Search