示例#1
0
    // Takes the group of enemies and creates EnemyToSpawn objects with the location
    // within the spawn zone of where to spawn them
    private void PopulateSpawnZone(EnemyGroup group, SpawnZone spawnZone)
    {
        List <GameAgentStats> enemyStats         = group.GetEnemiesStatsForSpawn();
        List <Pos>            zoneTiles          = spawnZone.GetUnpopulatedZoneTiles();
        List <Pos>            populatedZoneTiles = new List <Pos>();

        // Random distribution in zone
        List <int> exclusion = new List <int>();

        foreach (GameAgentStats stats in enemyStats)
        {
            int randomIndex = Utility.GetRandomIntWithExclusion(0, zoneTiles.Count - 1, rng, exclusion);
            Pos enemyPos    = new Pos((int)zoneTiles[randomIndex].x, (int)zoneTiles[randomIndex].y);
            populatedZoneTiles.Add(zoneTiles[randomIndex]);
            EnemyToSpawn enemy = new EnemyToSpawn(enemyPos, stats);

            exclusion.Add(randomIndex);
            enemies.Add(enemy);
        }
        spawnZone.PopulateTiles(populatedZoneTiles);
    }