Time for action – spawning enemies

  1. Add the SpawnEnemy() method to the EnemyManager class:
    public void SpawnEnemy(int path)
    {
        Enemy thisEnemy = new Enemy(
            texture,
            pathWaypoints[path][0],
            initialFrame,
            frameCount);
        for (int x = 0; x < pathWaypoints[path].Count(); x++)
        {
            thisEnemy.AddWaypoint(pathWaypoints[path][x]);
        }
        Enemies.Add(thisEnemy);
    }
  2. Add the SpawnWave() method to the EnemyManager class:
    public void SpawnWave(int waveType)
    {
        waveSpawns[waveType] +=
            rand.Next(MinShipsPerWave, MaxShipsPerWave + 1);
    }
  3. Add the updateWaveSpawns() method to the EnemyManager class:
    private void updateWaveSpawns(GameTime gameTime) { shipSpawnTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; if (shipSpawnTimer > shipSpawnWaitTime) { for (int x = waveSpawns.Count ...

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.