Skip to content

Commit

Permalink
Added methods for UI team giving a timeStamp of when the next mobs wi…
Browse files Browse the repository at this point in the history
…ll be spawned in WaveService.java. Also made the wave start timestamp update in LevelWaves.java (the first time waves are made) & in WaveTask.java (For when a wave ends and a new one starts).
  • Loading branch information
max9753 committed Sep 30, 2023
1 parent 1dd91e6 commit 60ff3da
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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();
}
Expand Down
35 changes: 35 additions & 0 deletions source/core/src/main/com/csse3200/game/services/WaveService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class WaveService {

private boolean levelCompleted = false;

private long nextWaveTime;


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

0 comments on commit 60ff3da

Please sign in to comment.