Package com.csse3200.game.entities
Class WaveManager
java.lang.Object
com.csse3200.game.entities.WaveManager
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static interface
-
Constructor Summary
ConstructorsConstructorDescriptionWaveManager
(EntitySpawn entitySpawn) Test-only constructor to inject a preconfiguredEntitySpawn
.WaveManager
(String levelKey) -
Method Summary
Modifier and TypeMethodDescriptionvoid
endWave()
Ends the current wave and immediately begins the next one.int
Gets the number of waves configured for the current level.int
int
int
int
Returns the enemy spawn attributes (cost + chance) for the current wave.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.int
Returns the minimum number of enemies to spawn for the current wave.float
float
int
getWaveCountForLevel
(String levelKey) Gets the number of waves configured for a specific level.int
Returns the configured weight/budget for the current wave.void
Advances to the next wave, resets internal state and lane sequence, and computes the number of enemies to spawn for this wave.boolean
boolean
void
Called when an enemy is disposed/destroyed.void
Resets the level state for starting a new level.void
Resets the WaveManager to its initial state for a fresh game start.void
setCurrentLevel
(String levelKey) Sets the current level.void
void
void
spawnEnemy
(int laneNumber) Spawns a single enemy of the next type in the provided lane.void
update
(float deltaTime) Update function to be called by main game loop.
-
Constructor Details
-
WaveManager
-
WaveManager
Test-only constructor to inject a preconfiguredEntitySpawn
. 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
-
setWaveEventListener
-
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
- Returns:
- current level key
-
setCurrentLevel
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
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 interfaceWaveConfigProvider
- 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 interfaceWaveConfigProvider
- Returns:
- the minimum number of enemies to spawn for the current wave
-
getEnemyConfigs
Returns the enemy spawn attributes (cost + chance) for the current wave.- Specified by:
getEnemyConfigs
in interfaceWaveConfigProvider
- Returns:
- the enemy spawn attributes (cost + chance) for the current wave.
-