Skip to content

Commit

Permalink
Added minimum time to pass for another engineer to spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandmcneilly committed Oct 14, 2023
1 parent 3d08ddf commit 9ae9c50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 16 additions & 0 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.csse3200.game.components.ProjectileEffects;

import com.csse3200.game.services.GameTime;
import com.csse3200.game.utils.math.RandomUtils;
import com.csse3200.game.services.ResourceService;
import com.csse3200.game.services.ServiceLocator;
Expand All @@ -27,6 +28,11 @@ public class ForestGameArea extends GameArea {
private static final int NUM_GRUNTS = 5;
private static final int NUM_BOSS = 4;

/* Change below to change the number of ms between spawns of engineers in the case */
private static final long ENGINEER_MIN_SPAWN_INTERVAL = 1000;

private long lastSpawnTime = 0;

private SecureRandom rand = new SecureRandom();

private int wave = 0;
Expand Down Expand Up @@ -963,10 +969,20 @@ private void spawnIncome() {
* and trigger engineer spawning
*/
private void spawnGapScanners() {
GameTime gameTime = ServiceLocator.getTimeSource();
long currSpawnTime = gameTime.getTime();
long diff = currSpawnTime - this.lastSpawnTime;

// Don't spawn an engineer if not enough time has passed
if (diff < ENGINEER_MIN_SPAWN_INTERVAL) {
return;
}

for (int i = 0; i < terrain.getMapBounds(0).y; i++) {
Entity scanner = GapScannerFactory.createScanner();
spawnEntityAt(scanner, new GridPoint2(0, i), true, true);
}
this.lastSpawnTime = currSpawnTime;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class LevelSelectScreen extends ScreenAdapter {
private Music music;

// Stores a time to determine the frame of the planet
// TODO: Account for integer overflow
float timeCounter = 0;

private static final String BG_PATH = "planets/background.png";
Expand Down

0 comments on commit 9ae9c50

Please sign in to comment.