Game Development Reference
In-Depth Information
_upComingEnemies.Add(new EnemyDef("up_l", 8));
_upComingEnemies.Add(new EnemyDef("down_l", 7));
_upComingEnemies.Add(new EnemyDef("up_l", 6));
// Sort enemies so the greater launch time appears first.
_upComingEnemies.Sort(delegate(EnemyDef firstEnemy, EnemyDef
secondEnemy)
{
return firstEnemy.LaunchTime.CompareTo(secondEnemy.LaunchTime);
});
}
Try out the level; you may find it a little challenging so this is a great time to play
around with the code and balance the game a little. Try increasing the player
firing rate or the spaceship speed.
Enemy Attacks
Enemies move in interesting ways across the level, but they're still quite passive.
The player can blast away at them and they do nothing! The enemies should have
some kind of recourse, so in this section we'll look at turning the tables a little.
There's already a BulletManager , and this currently handles only the player
bullets. The enemy bullets will only affect the player, and the player bullets will
only affect the enemies. For this reason, it's easiest to have separate lists of
bullets. This means a few of the functions need to be generalized to accept a list of
bullets.
public class BulletManager
{
List < Bullet > _bullets ¼ new List < Bullet > ();
List < Bullet > _enemyBullets ¼ new List < Bullet > ();
// Code omitted
public void Update(double elapsedTime)
{
UpdateBulletList(_bullets, elapsedTime);
UpdateBulletList(_enemyBullets, elapsedTime);
}
 
Search WWH ::




Custom Search