Time for action – updating and drawing the EnemyManager

  1. Add the Update() method to the EnemyManager class:
    public void Update(GameTime gameTime)
    {
        EnemyShotManager.Update(gameTime);
    
        for (int x = Enemies.Count - 1; x >= 0; x--)
        {
            Enemies[x].Update(gameTime);
            if (Enemies[x].IsActive() == false)
            {
                Enemies.RemoveAt(x);
            }
            else
            {
                if ((float)rand.Next(0, 1000) / 10 <= shipShotChance)
                {
                    Vector2 fireLoc = Enemies[x].EnemySprite.Location;
                    fireLoc += Enemies[x].gunOffset;
    
                    Vector2 shotDirection =
                        playerManager.playerSprite.Center -
                        fireLoc;
    
                    shotDirection.Normalize();
                    EnemyShotManager.FireShot(
                        fireLoc, 
                        shotDirection, 
                        false);
                }
            }
        }
    
        if (Active)
        {
            updateWaveSpawns(gameTime);
        }
    }
  2. Add the Draw() method to the EnemyManager class:
    public void Draw(SpriteBatch spriteBatch) ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.