How to make a wave system, if I need to spawn different enemies (enemy1, enemy2, enemy3…) in multiple combinations, also sometimes with pauses. How should I make an algorithm for waves? By the way, I require infinite spawning system. It should look like:
wave 1: spawn 10 X enemy1
wave 2: spawn 20 X enemy1
wave 3: spawn 20 X enemy1, spawn 10 X enemy2
wave 4: spawn 20 X enemy1, Wait 5 seconds, spawn 20 X enemy2
wave 5: spawn 30 X enemy2
wave 6: spawn 30 X enemy1, Wait 5 seconds, spawn 10 X enemy3
With greater wave number - greater amount of enemies and they should be spawned in various combinations, but later in some waves enemies should be spawned of the same type, abilities.
Recycle functions with similar enemies if they use linear increments or any logical pattern really.
Say you spawn 10 dragons, then if the next time you use that type of wave, you’d like to spawn 15 dragons instead, do something like this…
initially…
int dragons = 2;
then in your function
void SpawnDragons () {
int i = 5*dragons;
while (i < dragons) {
//spawnyourstuff
i++;
}
dragons++;
}
If you have many different types of waves that you want to cycle through, create an int, then check which function should be called based on that int’s value.
initially…
int spawnWave;
In your function that checks which wave function to call…
if(spawnWave == 0) {
cast x function;
}
else if(spawnWave == 1) {
cast y function
}
Then at the end of your functions, add this to reset the wave, or create a function for this instead of repeating it n times if you have many spawning functions.
if (spawnWave == "the amount of functions you wish to use") {
spawnWave = 0;
}
else {
spawnWave++;
}
For my game I made a few “difficulty” arrays and filled them with enemies of appropriate type. Then spawned difficulty 1 for about 3 times, picking random enemies inside the array each wave, then switched to the next array and did the same, all the way until reaching the last array.
My system wasn’t infinite but if it was, to keep things getting harder I’d increase the number of enemies being spawned, shorten the time between them, and maybe even throw in weaker enemy arrays.
I used coroutines for time between a spawn, and time between waves, but eventually I opted for letting the player hit “Next Wave” button to proceed.