Skip to content

Commit

Permalink
Merge branch 'main' into Team-5--Bug-Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasakev committed Oct 11, 2023
2 parents ef486ab + 7d8efa9 commit 9fc9dc3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
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 9fc9dc3

Please sign in to comment.