Tutorial Waves
It’s usually a good idea to introduce the different elements of your game gradually over time rather than throwing everything at the player from the very start. That way the player will get acquainted with the controls as well as the different enemy types and their different behaviors.
Our tutorial consists of five waves. The first four introducing the different enemy types and the last introducing a combination of these before the game proper starts. Each wave has a three second interval between them. The next wave will spawn even if the previous has not been defeated. The reason for keeping the waves so frequent is to keep down the time of the tutorial as well as set the pacing of the game already in the tutorial, even if it starts out a little slower.
So how did I implement these waves? I made the game state update method call on the method “Tutorial” when the game started. The game knew to only call on the “Tutorial” method because a Boolean (variable that can only be true or false) named “m_tutorialState” is set to “true”. The “tutorial” method counts down a “tutorial timer”, and when that timer reaches zero, “m_tutorialState” is set to “false”. When “m_tutorialState” is “false”, the game states’ update method calls on the method “RealTime”, which contains the code for the regular gameplay, instead.
The “Tutorial” method then spawns a preset number of enemies at three second intervals. The same timer used for this is the same timer used to determine when the “m_tutorialState” Boolean should be switched to false. Each wave has its own Boolean variable as well, that is switched to “true” as soon as it is spawned the first time, which prevents it happening again. The code looks like this:
If (m_wave == false && m_tutorialTimer >= 3.0)
{
m_wave = true;
m_entitiyManager->AddEnemyAOE(m_spawnerAOEenemy->Spawn());
}
The reason for using Booleans here as well is because if you try to make it happen between, say, 3.0 and 3.1 seconds, then there is a good chance it will happen more than once because each loop has a very short duration. You could try to counteract this by making the step smaller, for example between 3.0 and 3.01. The problem with this is twofold. First off, if you make the step too small then this wave will most likely be skipped over. Second, each waves’ duration varies, making it even harder to make an interval in time that will only happen once. Better to use Booleans as a form of “lock” on the if-statements.
Cheers!