Wave spawning
I was wondering how to do waves in my game. I think I got it. I'll try my best to write it down in a way I understand later.
Waves are defined using patterns, enemy count and spawn intervals. Each wave has all 3 of these and a change in at least one attribute changes how difficult the wave is.
Patterns: Patterns are going to be like several overloaded functions. I can define my patterns and put any type of enemies into this. For example, if I define the pattern for wave 1 as
WavePattern(x, t, enemy1)
, it's going to mean that there's going to be an x amount of enemy1 type enemies with an interval of t amount of time. But if I do it likeWavePattern(x, t, enemy1, enemy2)
, it's an overloaded method, and it will spawn the same number of enemies with the same gap, but each third enemy in the wave will be replaced by enemy2. That results in a wave that goes like e1, e1, e2, e1, e1, e2, e1, e1, ... and so on. The parameter for the 2nd enemy may vary according to how I create the function. Based on how this overload works, if I type in a functionWavePattern(x, t, enemy1, enemy2, enemy3, enemy4, enemy5)
, the wave is going to look like this:e1, e1, e2, e1, e3, e2, e4, e1, e2, e3, e5, ...
If you look closely, the next enemy type on the parameter order is replacing every nth enemy in the wave ('n' being prime numbers). I need to identify a good mathematical pattern for this. Here are some for future reference:
Prime: 1, 3, 5, 7, 11, 13, 17, 19, 23, 31, ...
Square: 1, 4, 8, 16, 32, 64, 128, ... (This seems a little too excessive, but who knows)
Triangular: 1, 3, 6, 10, 15, 21, 28, 36, 45, ... (This seems promising)
And here's another thought. Rather than replacing enemies, what if I ADD an enemy of the next type after every 'n' number of enemies? This way, there will be more enemies for the wave than the enemy count. The enemy count would only apply to the first parameterized enemy. Here's how it'll look with a triangular pattern:
e1 e1 e1 e2 e1 e1 e1 e2 e3 e1 e1 e1 e2 e1 e3 e1 e1 e2 e3 e1 e1 e1 e2 e4, ...
I know it's hard to read but it is doing what I've stated above. An E2 enemy will be spawned after every 3 E1 enemy and an E3 enemy will be spawned after every 6 E1 enemy.
OR I could make it like an E2 enemy will be REPLACING every 3rd E1 enemy, and an E3 enemy will be replacing every 3rd E2 enemy. Maybe this is better. This way, the enemy count will not change, and no enemies will be added. Also, the pattern wouldn't be super-obvious since once in a while, the replacement intervals of 2 enemy types would overlap and then also push the next spawn of a rarer enemy even further away.
Wait... That might also be a problem. Maybe I can pre-run the function to get an array of how the wave would spawn according to patterns, and then reverse the order? That way, there will be fewer rare enemies at first but more towards the end of the wave.
I guess there won't be just one pattern (ex: triangular). I will define the pattern per wave in the 'wave_data' file. Here are some patterns I can think of:
single: When there is only one type of enemy per wave.
third_replace: Every 3rd enemy is replaced by the previous enemy type.
prime_add: Each enemy is assigned a spawn rate based on prime numbers. A new enemy is added instead of replaced.
triangular_add: Each enemy is assigned a spawn rate based on triangular numbers. A new enemy is added instead of replaced.