-
Notifications
You must be signed in to change notification settings - Fork 4
WaveTask
The WaveTask
is attached to a non-visible wave entity and contains the functionality to begin a new wave, or continue an existing one, depending on if there are mobs still alive. It also manages the sound effects which occur when a wave begins and ends.
The WaveTask
is an AI Task, so is added to an entity in WaveFactory
. When the arrangement of waves are made for a level, the task is attached to the level in the factory. This allows the function to constantly run and check what it should do next.
The two main methods in WaveTask
are start()
and update()
, which are explained in detail below.
When the level begins, this method is run and creates the first wave instance. It retrieves the currentWave
from LevelWaves
and sets the initial count of mobs in WaveService
to be the size of the current wave. This is shown in the code snippet below:
@Override
public void start() {
super.start();
this.owner.getEntity().getEvents().addListener("waveFinishedSpawning", () -> waveInProgress = false);
this.waveInProgress = true;
this.level = (LevelWaves) this.owner.getEntity();
this.currentWave = level.getWave(currentWaveIndex);
ServiceLocator.getWaveService().setEnemyCount(currentWave.getSize());
logger.info("Wave {} starting with {} enemies", currentWaveIndex, ServiceLocator.getWaveService().getEnemyCount());
}
This method runs in the background of the game, and checks whether there are still mobs remaining from the previous wave. If there are still mobs left, it continues the current wave, but if they have all died, we must either begin another wave or check if the level has been completed.
The level is completed if currentWaveIndex == this.level.getNumWaves()
, which is retrieved from LevelWaves
. If this condition is met, we are prompted to a Level Completed UI (still to be implemented). If this statement is not true, then this means we still have some waves left to run, so we move onto the next wave, as shown below:
logger.info("No enemies remaining, begin next wave");
this.waveInProgress = true;
this.level.setWaveIndex(currentWaveIndex);
this.currentWave = this.level.getWave(currentWaveIndex);
ServiceLocator.getWaveService().setEnemyCount(currentWave.getSize());