Class WaveManager

java.lang.Object
com.csse3200.game.entities.WaveManager
All Implemented Interfaces:
WaveConfigProvider

public class WaveManager extends Object implements WaveConfigProvider
Manages the lifecycle of enemy waves and schedules spawns over time.

WaveManager is a lightweight coordinator:

  • Tracks the current wave number and whether a wave is active.
  • Determines spawn cadence and a fair, shuffled lane sequence.
  • Asks EntitySpawn to compute how many enemies a wave should produce and which type to spawn next.
  • Delegates the actual entity creation and placement via callback interface.

This class does not construct enemies nor touch rendering; it only orchestrates when/where to request a spawn.

  • Constructor Details

    • WaveManager

      public WaveManager(String levelKey)
    • WaveManager

      public WaveManager(EntitySpawn entitySpawn)
      Test-only constructor to inject a preconfigured EntitySpawn. Useful for unit tests that avoid LibGDX file IO.
      Parameters:
      entitySpawn - spawn helper used by this manager
  • Method Details

    • initialiseNewWave

      public void initialiseNewWave()
      Advances to the next wave, resets internal state and lane sequence, and computes the number of enemies to spawn for this wave. Starts with a preparation phase.
    • endWave

      public void endWave()
      Ends the current wave and immediately begins the next one. External systems listen to wave change events for UI updates.
    • setEnemySpawnCallback

      public void setEnemySpawnCallback(WaveManager.EnemySpawnCallback callback)
    • setWaveEventListener

      public void setWaveEventListener(WaveManager.WaveEventListener listener)
    • getCurrentWave

      public int getCurrentWave()
    • isPreparationPhaseActive

      public boolean isPreparationPhaseActive()
      Returns:
      true if currently in preparation phase
    • getPreparationPhaseRemainingTime

      public float getPreparationPhaseRemainingTime()
      Returns:
      remaining time in preparation phase (0 if not in preparation phase)
    • getPreparationPhaseDuration

      public float getPreparationPhaseDuration()
      Returns:
      preparation phase duration in seconds
    • onEnemyDisposed

      public void onEnemyDisposed()
      Called when an enemy is disposed/destroyed. Updates the disposed counter and checks if the wave should end.
    • getEnemiesDisposed

      public int getEnemiesDisposed()
      Returns:
      number of enemies disposed in current wave
    • getEnemiesSpawned

      public int getEnemiesSpawned()
      Returns:
      number of enemies spawned in current wave
    • isLevelComplete

      public boolean isLevelComplete()
      Returns:
      true if all waves for the current level have been completed
    • resetLevel

      public void resetLevel()
      Resets the level state for starting a new level. This should be called when switching to a different level.
    • resetToInitialState

      public void resetToInitialState()
      Resets the WaveManager to its initial state for a fresh game start. This should be called when starting a new game session.
    • getEnemiesRemaining

      public int getEnemiesRemaining()
      Returns:
      number of enemies remaining in current wave
    • getCurrentLevelKey

      public String getCurrentLevelKey()
      Returns:
      current level key
    • setCurrentLevel

      public void setCurrentLevel(String levelKey)
      Sets the current level. This should be called when loading a specific level.
      Parameters:
      levelKey - the level key to set
    • update

      public void update(float deltaTime)
      Update function to be called by main game loop. Handles preparation phase timer and enemy spawning.
      Parameters:
      deltaTime - time elapsed since last update in seconds
    • getLane

      public int getLane()
      Returns the next lane index from a pre-shuffled sequence, reshuffling when the sequence is exhausted to avoid long runs on the same lane.
      Returns:
      lane index in [0, 5]
    • spawnEnemy

      public void spawnEnemy(int laneNumber)
      Spawns a single enemy of the next type in the provided lane. Ends the wave once the configured number of spawns has been reached.
      Parameters:
      laneNumber - lane index to spawn into
    • getWaveCountForLevel

      public int getWaveCountForLevel(String levelKey)
      Gets the number of waves configured for a specific level.
      Parameters:
      levelKey - the level key to check
      Returns:
      the number of waves for that level
    • getCurrentLevelWaveCount

      public int getCurrentLevelWaveCount()
      Gets the number of waves configured for the current level.
      Returns:
      the number of waves for the current level
    • getWaveWeight

      public int getWaveWeight()
      Returns the configured weight/budget for the current wave.
      Specified by:
      getWaveWeight in interface WaveConfigProvider
      Returns:
      the configured weight/budget for the current wave
    • getMinZombiesSpawn

      public int getMinZombiesSpawn()
      Returns the minimum number of enemies to spawn for the current wave.
      Specified by:
      getMinZombiesSpawn in interface WaveConfigProvider
      Returns:
      the minimum number of enemies to spawn for the current wave
    • getEnemyConfigs

      public Map<String,BaseSpawnConfig> getEnemyConfigs()
      Returns the enemy spawn attributes (cost + chance) for the current wave.
      Specified by:
      getEnemyConfigs in interface WaveConfigProvider
      Returns:
      the enemy spawn attributes (cost + chance) for the current wave.