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 b98d7079d..4be3210de 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 @@ -18,6 +18,7 @@ public class WaveTask extends DefaultTask implements PriorityTask { private LevelWaves level; private WaveClass currentWave; private final GameTime globalTime; + private long nextWaveAt = 0; private int currentWaveIndex = 0; private boolean waveInProgress; private float startTime = 0; @@ -93,7 +94,7 @@ public void start() { @Override public void update() { if (ServiceLocator.getWaveService().getEnemyCount() == 0) { - currentWaveIndex++; +// currentWaveIndex++; long currentTime = ServiceLocator.getTimeSource().getTime(); // Setting the timestamp for when the next mobs will spawn. @@ -108,15 +109,28 @@ public void update() { } else { // Spawn the next wave - logger.info("No enemies remaining, begin next wave"); - this.waveEnd.play(); - this.waveInProgress = true; - this.level.setWaveIndex(currentWaveIndex); - // Set the service wave count to the current wave index. - ServiceLocator.getWaveService().setWaveCount(currentWaveIndex); - this.currentWave = this.level.getWave(currentWaveIndex); - ServiceLocator.getWaveService().setEnemyCount(currentWave.getSize()); - //endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000L); // reset end time +// logger.info("No enemies remaining, begin next wave"); + if (nextWaveAt == 0) { + logger.info("Next wave in 10 seconds"); + nextWaveAt = globalTime.getTime() + 10000; + ServiceLocator.getWaveService().setNextWaveTime(nextWaveAt); + } else { + if (globalTime.getTime() >= nextWaveAt || ServiceLocator.getWaveService().shouldSkip()) { + logger.info("Next wave starting"); + ServiceLocator.getWaveService().toggleDelay(); + currentWaveIndex++; + ServiceLocator.getWaveService().setNextWaveTime(0); + nextWaveAt = 0; + this.waveEnd.play(); + this.waveInProgress = true; + this.level.setWaveIndex(currentWaveIndex); + // Set the service wave count to the current wave index. + ServiceLocator.getWaveService().setWaveCount(currentWaveIndex); + this.currentWave = this.level.getWave(currentWaveIndex); + ServiceLocator.getWaveService().setEnemyCount(currentWave.getSize()); + //endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000L); // reset end time + } + } } } else { diff --git a/source/core/src/main/com/csse3200/game/entities/EntityService.java b/source/core/src/main/com/csse3200/game/entities/EntityService.java index b5fe3ce77..f45576fb0 100644 --- a/source/core/src/main/com/csse3200/game/entities/EntityService.java +++ b/source/core/src/main/com/csse3200/game/entities/EntityService.java @@ -183,6 +183,24 @@ public Entity getEntityAtPosition(float x, float y) { return null; } + /** + * Checks for the presence of an Entity at a specified position (x, y). + * + * @param x The x-coordinate of the position to check. + * @param y The y-coordinate of the position to check. + * @return The Entity found at the specified position, or null if no Entity is present. + */ + public Entity checkEntityAtPosition(int x, int y) { + entities.sort(Comparator.comparingInt(Entity::getLayer)); + for (Entity entity : entities) { + if (entity.getPosition().x == x && entity.getPosition().y == y) { + return entity; + } + } + return null; + } + + private boolean entityContainsPosition(Entity entity, float x, float y) { float entityX = entity.getPosition().x; float entityY = entity.getPosition().y; @@ -207,7 +225,7 @@ public boolean entitiesInTile(int x_coord, int y_coord) { return true; } if (mp.getCell(x_coord, y_coord) != null) { - Entity entity = getEntityAtPosition(x_coord, y_coord); + Entity entity = checkEntityAtPosition(x_coord, y_coord); return entity != null; } return true; 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 c00693fbd..c7ddacdef 100644 --- a/source/core/src/main/com/csse3200/game/services/WaveService.java +++ b/source/core/src/main/com/csse3200/game/services/WaveService.java @@ -19,6 +19,8 @@ public class WaveService { private int spawnDelay; + private boolean skipDelay = false; + /** * Constructor for the Wave Service @@ -136,11 +138,26 @@ public void setNextWaveTime(long nextWaveTime) { public int getSpawnDelay() {return this.spawnDelay;} - /* Used for adding this instance of UIElementsDisplay to the mainGameScreen. This is needed as update is performed + /** + * Used for adding this instance of UIElementsDisplay to the mainGameScreen. This is needed as update is performed * for this instance of the display. * @return the updating instance of UIElementsDisplay */ public UIElementsDisplay getDisplay() { return this.display; } + + /** + * This will invert the value of the skipDelay boolean + * */ + public void toggleDelay() { + this.skipDelay = !this.skipDelay; + } + + /** + * retrieve the skipDelay condition + * */ + public boolean shouldSkip() { + return this.skipDelay; + } }