Project 1: Space Shooter

Making the game incrementally harder

By introducing a wave system

Eero Saarinen

--

Gameplay showing the waves spawning as intended, at the bottom can be seen a log-message showing when the enemies for the current wave have been spawned.
The waves spawning as intended, at the bottom can be seen a log-message showing when the enemies for the current wave have been spawned.

Now that all the enemies are done and the player has a sufficient amount of weapons and features it is time to make the game feel like one.

The game already has coroutines to endlessly spawn enemies and power ups, while this might be a fun game mode, there still is satisfaction to be found when the player reaches higher and higher wave counts.

To make this happen I introduce a new coroutine called SpawnWavesRoutine to handle more controlled spawning. In the beginning of the coroutine variables that are used later are defined, the first wave number is shown to the player followed by a six second wait, after which both of the spawn routines are started. The spawn routines for the enemies and the power ups are given variable names, so that they can be stopped at the right times.

Showing the SpawnWavesRoutine coroutine.
The SpawnWavesRoutine coroutine.

The routine will then run as long as the wave number is less than or equal to the total number of waves, this is set five for now. The enemies will be spawned as long as their number totals the number of enemies in that wave.

The int type variable _enemiesSpawned is incremented by one after each enemy instantiation inside the SpawnEnemyRoutine. The amount of enemies in a wave is equal to the base number of enemies, set to five, multiplied by the wave number.

The Boolean flag allEnemiesSpawned is set to true once all of the enemies for the current wave have been spawned. This is then used to determine if the wave is over with the information that all the enemies have been killed, which can be determined if the _enemyContainer has no children.

The container was originally used to clean up the Hierarchy of clutter, but it also provides a handy way to check if all the enemies are killed once all of them have been spawned.

As long as the wave number is less than the total number, a new wave is started. The only difference is that the wave count is incremented by one, the rest is more or less the same.

To keep the coroutine running, at the very end outside of all the if-statements the while-loop will wait for one second for the enemies to spawn. The wait time was arbitrarily chosen, and could most likely be a shorter time.

--

--