The enemy wave spawning algorithm itself (that is the algorithm that handles when new enemy waves are spawned and how said process of spawning new enemy waves is executed) really hasn't changed much.

Random waves are still drawn from a list and their enemies spawned accordingly every time there are no offensive enemies (that is enemies that attack the player) in the scene. The only major difference here (as you can probably see in this snippet) is that the random waves are no longer drawn directly from the waves array that is accessible in the inspector window but instead from a separate internal list of waves that is built on Start and re-built every 10 waves during runtime.

The process of doing so can be separated into two subparts, adding new waves and pruning waves that are too easy for the point in the round the player has reached, this is in order to keep things exciting for the player, of course!
Waves added are based on a new wave difficulty system. Each enemy now holds it's own difficulty value and the difficulty of a wave is simply the sum of it's enemies' difficulty values.

Every time the internal list from which waves shall be drawn is updated, I loop through the FULL list of waves (the one I can modify in the inspector window) and add any waves that have a difficulty value less than the player's score divided by five (keep in mind the players score and the difficulty of enemies are both integers so this is an integer division operation) plus three to the list skipping any wave configurations that are already present in the list.
For example, when the player's score is less than five, the max difficulty of a wave that can spawn is two, meaning at most two soldiers can spawn until you reach a score of 10 where the list is next updated since soldiers have a difficulty value of one. Beetles have a difficulty value of two but all configurations involving them also include at least two soldiers so they don't spawn until you've gotten 10 points and the list is updated again (at this point waves with a difficulty leq 4 are added to the random draw list)

Pruning "easy" waves creates a brand new list from the current one where any waves with a difficulty value less than the players score over five minus five are left out (this proved more intuitive, at least to me, than trying to REMOVE items and since this is only being carried out every 10 waves I wasn't TOO concerned with the runtime complexity, after all, I can always have this happen more rarely by changing the value by which I mod the wave number in figure one).
This created a potential problem I noticed almost immediately, however, where eventually the players score would get to a point where there were literally NO waves that could meet this requirement and they'd all be left out. In order to fix this, I went ahead and made it so they'd also be included if their difficulty was five or greater regardless of the player's score. This seemed totally fine as the straight row of five and any wave with at least three soldiers and a beetle are a difficulty of five, both of which are REASONABLY challenging waves and shouldn't feel too boring to have spawn on you late-game (again, I can always tweak some values later if I need to so shrug).















0 comments