diff --git a/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java b/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java index a4a4aaabb..2c0743b22 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java @@ -33,6 +33,12 @@ public LevelWaves(int spawnDelay) { this.mobIndex = 0; this.waveIndex = 0; this.numWaves = 0; + + long currentTime = ServiceLocator.getTimeSource().getTime(); + // Setting the timestamp for when the next mobs will spawn. + // Currently, the delay of mobs spawning after wave start + // is hardcoded but will fix in the next push. + ServiceLocator.getWaveService().setNextWaveTime(currentTime + 10000); } /** @@ -89,4 +95,13 @@ public void setWaveIndex(int index) { public int getNumWaves() { return this.numWaves; } + + public float getSpawnDelay() { + return this.spawnDelay; + } + + public long getStartTime() { + return this.startTime; + } } + diff --git a/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java b/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java index 5ffcfdea9..6ea948ba4 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java @@ -95,6 +95,12 @@ public void update() { if (ServiceLocator.getWaveService().getEnemyCount() == 0) { currentWaveIndex++; + long currentTime = ServiceLocator.getTimeSource().getTime(); + // Setting the timestamp for when the next mobs will spawn. + // Currently, the delay of mobs spawning after wave start + // is hardcoded but will fix in the next push. + ServiceLocator.getWaveService().setNextWaveTime(currentTime + 10000); + // Check if level has been completed - no more waves remaining if (currentWaveIndex == this.level.getNumWaves()) { logger.info("No waves remaining, level completed"); @@ -116,6 +122,8 @@ public void update() { } else { logger.info("{} enemies remaining in wave {}", ServiceLocator.getWaveService().getEnemyCount(), currentWaveIndex); logger.info("WAVE SERVICE NUMBER: Wave Number {}",ServiceLocator.getWaveService().getWaveCount()); + logger.info("NEXT WAVE AT {}", ServiceLocator.getWaveService().getNextWaveTime()); + logger.info("TIME IS {}", ServiceLocator.getTimeSource().getTime()); if (waveInProgress) { this.level.spawnWave(); } diff --git a/source/core/src/main/com/csse3200/game/services/WaveService.java b/source/core/src/main/com/csse3200/game/services/WaveService.java index d09aa98d7..cd26acf8b 100644 --- a/source/core/src/main/com/csse3200/game/services/WaveService.java +++ b/source/core/src/main/com/csse3200/game/services/WaveService.java @@ -13,6 +13,8 @@ public class WaveService { private boolean levelCompleted = false; + private long nextWaveTime; + /** * Constructor for the Wave Service @@ -58,10 +60,18 @@ public void setLevelCompleted() { } } + /** + * Sets the waveCount + * @param lane as an integer representing the next lane of a mob. + */ public void setNextLane(int lane) { this.lane = lane; } + /** + * Returns the next lane number of a mob + * @return (int) lane number + */ public int getNextLane() { return lane; } @@ -74,11 +84,36 @@ public boolean isLevelCompleted() { return levelCompleted; } + /** + * Returns the game over state + * @return (boolean) true if the game is over; false otherwise + */ public int getWaveCount() { return this.waveCount; } + /** + * Sets the waveCount + * @param waveCount as an integer representing the current wave number. + * This will be added to the current wave number. + */ public void setWaveCount(int waveCount) { this.waveCount += waveCount; } + + /** + * Returns time of the next wave. + * @return (long) A timestamp of when the next mobs will spawn. Used for UI elements. + */ + public long getNextWaveTime() { + return this.nextWaveTime; + } + + /** + * Sets the next wave timestamp + * @param nextWaveTime as a long which is the time when then next mobs will spawn. + */ + public void setNextWaveTime(long nextWaveTime) { + this.nextWaveTime = nextWaveTime; + } }