I moved to a new URL! Check it out!

Dev Log: Enemy Waves

Dev Log: Enemy Waves
Waves of enemies can be a pretty confusing thing to manage. It sounds simple at first, but the amount of ways that you can manage a group of enemies entering the game seems nearly endless. Usually in games where I have waves of enemies I don't have enough time to think of an elegant solution. I just usually end up with some sort of random enemy generator and over time I add more potential enemy types to the pool. This works most of the time but can often lead to really weird patterns, or nearly impossible to survive scenarios if its not tuned correctly.

For this game I have a little bit more time than a weekend to complete it, so this gives me an opportunity to try and come up with a cool solution. For the current design of the game there exist enemy spawner tiles in the game world. These tiles are present from the very start of the session, although all of them might not be active yet.

Enemies can spawn from any one of the active tiles in the scene. There is always at least one active enemy spawner from the start. An enemy wave consists of a list of enemies, and each one of those list entries also knows what enemy spawner they should come from, and how long they should wait before appearing.

When I have a wave ready to go I can add it into my EncounterManager object which will then execute each wave. An enemy wave can either wait for a certain amount of time before spawning the next one, or it can wait for all of the enemies to be cleared before spawning the next one.

So with all of that, this is what it currently looks like to set up enemy waves:
var wave2 = new EnemyWaveProperties()
.Add(typeof(EnemyBitty))
.SpawnFrom(1)
.Add(typeof(EnemyBitty))
.SpawnFrom(0)
.Delay(120)
.Add(typeof(EnemyPopcorn))
.SpawnFrom(1)
.Add(typeof(EnemyPopcorn))
.Delay(120)
.SpawnFrom(0)
.Add(typeof(EnemyBitty))
.Add(typeof(EnemyBitty))
.Add(typeof(EnemyBitty));

EncounterManager.AddAction(new EncounterActionEnemyWave(wave2));
And here's a quick look at what it looks like when the encounter manager is executing an enemy wave action.
public override void Execute() {
foreach(var wave in properties.Waves) {
var spawner = EnemySpawner.GetSpawnerById(wave.SpawnerId);

foreach (var waveEnemy in wave.Enemies) {
if (Spawning) {
if (Timer == waveEnemy.SpawnDelay) {
var enemy = spawner.Spawn(waveEnemy.EnemyType);
EnemiesSpawned.Add(enemy);
SpawnedFirstEnemy = true;
}
}
}
}

if (Timer >= properties.MaxSpawnDelay) {
Spawning = false;
}

if (WaitForClear && SpawnedFirstEnemy) {
var enemiesDead = true;
foreach (var enemy in EnemiesSpawned) {
if (enemy.IsInScene) { // Enemy is still alive
enemiesDead = false;
}
}
if (enemiesDead) {
Finished = true;
EnemiesSpawned.Clear();
}
}
else {
if (Timer >= Time) {
Finished = true;
}
}

Timer++;
}
Nothing too crazy, I think!

Comments

Jake Albano
Jake Albano
StratoForce, huh? :O Game has name?

This is a pretty neato system! It reminds me of this thing Chevy did a while ago: http://indiehouse.tumblr.com/post/42285771265/spawn-patterns. I'd recommend incorporating some similar kind of data-driven system for setting this stuff up; then you can change patterns without having to restart the game. Super good for reducing teration times!
Posted April 24th 2014 11:01 PM
Jake Albano
Jake Albano
Bah, "iteration". Edit button why u no
Posted April 24th 2014 11:02 PM
Kyle
Kyle
Edit button jeez then I'd have to keep track of people with sessions or something ugahisdghi

I'll make this data driven at some point. I might be procedurally generating missions so we'll see if I even need to do that.
Posted April 25th 2014 1:44 AM
new comment!

Post your comment!

Name
Email
Comment