Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team 4 waves #227

Merged
merged 3 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}