Spawning waves of enemies
Before we discussed the tower and enemy behaviors, we parsed an XML file containing the various hordes or waves of enemies that the player would have to face in a given level. Now it's time to code in the logic of actually spawning a wave and its constituent enemies. A wave may be spawned after any previous wave has completed or when the level has just begun. Let's take a look at the spawning of a wave in the StartNextWave
function of GameWorld.cpp
:
void GameWorld::StartNextWave(float dt) { // increment the current wave index ++ curr_wave_index_; // are there any waves left? if(curr_wave_index_ >= num_waves_) { // level has completed GameOver(true); } else { // start the next wave in a few seconds curr_wave_ = waves_[curr_wave_index_]; schedule(schedule_selector(GameWorld::SpawnEnemy), curr_wave_->spawn_delay_); UpdateHUD(); GameGlobals::ScaleLabel(waves_label_); } }
The reason that the StartNextWave
function...