Skip to content

Commit

Permalink
Merge branch 'main' into Mohamad-Maps
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamad11Dab committed Oct 6, 2023
2 parents 962fa12 + 3e31d95 commit a174583
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
19 changes: 18 additions & 1 deletion source/core/src/main/com/csse3200/game/services/WaveService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class WaveService {

private int spawnDelay;

private boolean skipDelay = false;


/**
* Constructor for the Wave Service
Expand Down Expand Up @@ -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;
}
}

0 comments on commit a174583

Please sign in to comment.