Skip to content

Commit

Permalink
Added waves with 10 seconds interval
Browse files Browse the repository at this point in the history
  • Loading branch information
DevenBhasin committed Sep 9, 2023
1 parent b854637 commit a7e855e
Showing 1 changed file with 47 additions and 9 deletions.
56 changes: 47 additions & 9 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ public class ForestGameArea extends GameArea {
private static final int NUM_GHOSTS = 0;
private static final int NUM_GRUNTS = 5;

private static final int NUM_BOSS=4;
private static final int NUM_BOSSKING2=2;
private static final int NUM_BOSSKING1=2;

private Timer bossSpawnTimer;
private int bossSpawnInterval = 10000; // 1 minute in milliseconds

private int wave = 0;
private Timer waveTimer;

private static final int NUM_WEAPON_TOWERS = 3;
private static final GridPoint2 PLAYER_SPAWN = new GridPoint2(0, 0);
Expand Down Expand Up @@ -135,6 +137,37 @@ public class ForestGameArea extends GameArea {
private Entity bossKing1;
private Entity bossKing2;

// Add this method to start the wave spawning timer when the game starts.
private void startWaveTimer() {
waveTimer = new Timer();
waveTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
spawnWave();
}
}, 0, 10000); // 10000 milliseconds = 10 seconds
}

// Add this method to stop the wave timer when the game ends or as needed.
private void stopWaveTimer() {
if (waveTimer != null) {
waveTimer.cancel();
waveTimer = null;
}
}

private void spawnWave() {
wave++;
switch (wave) {
case 1, 2 -> spawnXenoGrunts();
case 3 -> spawnBossKing1();
case 4 -> spawnBossKing2();
default -> {
}
// Handle other wave scenarios if needed
}
}


/**
* Initialise this ForestGameArea to use the provided TerrainFactory.
Expand Down Expand Up @@ -166,8 +199,7 @@ public void create() {
spawnGhosts();
spawnWeaponTower();
spawnEngineer();
bossKing1 = spawnBossKing1();
bossKing2 = spawnBossKing2();
startWaveTimer();
spawnTNTTower();
}

Expand Down Expand Up @@ -267,10 +299,15 @@ private void spawnGhosts() {
private Entity spawnBossKing1() {
int[] pickedLanes = new Random().ints(0, 8)
.distinct().limit(5).toArray();
GridPoint2 randomPos = new GridPoint2(19, pickedLanes[0]);
Entity ghostKing = NPCFactory.createGhostKing(player);
spawnEntityAt(ghostKing, randomPos, true, true);
return ghostKing;
for (int i = 0; i < NUM_BOSSKING1; i++) {
GridPoint2 randomPos = new GridPoint2(19, pickedLanes[i]);
bossKing1 = BossKingFactory.createBossKing1(player);
spawnEntityAt(bossKing1,
randomPos,
true,
false);
}
return bossKing1;
}

/**
Expand Down Expand Up @@ -362,7 +399,7 @@ private Entity spawnBossKing2() {
int[] pickedLanes = new Random().ints(0, 8)
.distinct().limit(5).toArray();

for (int i = 0; i < NUM_BOSS; i++) {
for (int i = 0; i < NUM_BOSSKING2; i++) {
GridPoint2 randomPos = new GridPoint2(19, pickedLanes[i]);
bossKing2 = BossKingFactory.createBossKing2(player);
spawnEntityAt(bossKing2,
Expand Down Expand Up @@ -470,6 +507,7 @@ public void dispose() {
super.dispose();
ServiceLocator.getResourceService().getAsset(backgroundMusic, Music.class).stop();
this.unloadAssets();
stopWaveTimer();
}

private void spawnScrap() {
Expand Down

0 comments on commit a7e855e

Please sign in to comment.