Skip to content

Commit

Permalink
Fixes bugs in wave functionality and allows for different mob types
Browse files Browse the repository at this point in the history
  • Loading branch information
bojyyy committed Sep 28, 2023
1 parent 547562a commit a963180
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 22 deletions.
47 changes: 32 additions & 15 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public class ForestGameArea extends GameArea {
private final TerrainFactory terrainFactory;

private Entity player;
private Entity waves;

// Variables to be used with spawn projectile methods. This is the variable
// that should occupy the direction param.
Expand Down Expand Up @@ -262,13 +263,17 @@ public void create() {

// Set up infrastructure for end game tracking
player = spawnPlayer();
player.getEvents().addListener("spawnWave", this::spawnWave);

waves = WaveFactory.createWaves();
spawnEntity(waves);
waves.getEvents().addListener("spawnWave", this::spawnMob);

playMusic();
spawnXenoGrunts();
startWaveTimer();
//spawnXenoGrunts();
//startWaveTimer();
spawnScrap();
spawnDeflectXenoGrunt(15, 5);
spawnSplittingXenoGrunt(15, 4);
//spawnDeflectXenoGrunt(15, 5);
//spawnSplittingXenoGrunt(15, 4);
spawnScrap();
spawnTNTTower();
spawnWeaponTower();
Expand Down Expand Up @@ -476,17 +481,29 @@ private void spawnProjectile(Vector2 position, short targetLayer, int space, int
Entity Projectile = ProjectileFactory.createFireBall(targetLayer, new Vector2(direction, position.y + space), speed);
Projectile.setPosition(position);
spawnEntity(Projectile);
}

private void spawnXenoGrunts() {
int[] pickedLanes = random.ints(1, 7)
.distinct().limit(5).toArray();
for (int i = 0; i < NUM_GRUNTS; i++) {
GridPoint2 randomPos = new GridPoint2(19, pickedLanes[i]);
Entity xenoGrunt = NPCFactory.createXenoGrunt();
xenoGrunt.setScale(1.5f, 1.5f);
spawnEntityAt(xenoGrunt, randomPos, true, false);
}

public void spawnMob(String entity, GridPoint2 randomPos) {
Entity mob;
logger.info("Spawning Xeno {}");
switch (entity) {
case "Xeno":
mob = NPCFactory.createXenoGrunt();
break;
case "SplittingXeno":
mob = NPCFactory.createSplittingXenoGrunt();
break;
case "DodgingDragon":
mob = NPCFactory.createDodgingDragonKnight();
break;
case "DeflectXeno":
mob = NPCFactory.createDeflectXenoGrunt();
break;
default:
mob = NPCFactory.createBaseNPC();
}
mob.setScale(1.5f, 1.5f);
spawnEntityAt(mob, randomPos, true, false);
}

// * TEMPORARY FOR TESTING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void update() {
this.owner.getEntity().getEvents().trigger("dieStart");
currentTask.stop();
isDead = true;
ServiceLocator.getWaveService().updateEnemyCount();
}

// Check if the mob has finished death animation
Expand All @@ -85,8 +86,6 @@ else if (isDead && owner.getEntity().getComponent(AnimationRenderComponent.class
ServiceLocator.getEntityService().register(scrap);

// Delete the mob and update count for number of mobs remaining in the wave
ServiceLocator.getWaveService().updateEnemyCount();
logger.info("Number of enemies remaining: {}", ServiceLocator.getWaveService().getEnemyCount());
owner.getEntity().setFlagForDelete(true);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ else if (isDead && owner.getEntity().getComponent(AnimationRenderComponent.class
Entity scrap = DropFactory.createScrapDrop();
scrap.setPosition(mobPosition.x,mobPosition.y);
ServiceLocator.getEntityService().register(scrap);
ServiceLocator.getWaveService().updateEnemyCount();

// Delete the mob.
owner.getEntity().setFlagForDelete(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void spawnWave() {
do {
currentRandom = rand.nextInt(1, 7);
} while (currentRandom == previousRandom);
previousRandom = currentRandom;
GridPoint2 randomPos = new GridPoint2(19, currentRandom);
this.getEvents().trigger("spawnWave", waves.get(waveIndex)
.getMobs().get(mobIndex), randomPos);
Expand All @@ -51,6 +50,11 @@ public void spawnWave() {
previousRandom = currentRandom;
} else if (mobIndex == waves.get(waveIndex).getSize()) {
this.getEvents().trigger("waveFinishedSpawning");
mobIndex = 0;
}
}

public void setWaveIndex(int index) {
this.waveIndex = index;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public WaveTask() {
this.currentWaveIndex = 0;
this.waveInProgress = false;
loadSounds();
this.waveStart = ServiceLocator.getResourceService().getAsset(waveSounds[0], Sound.class);
this.waveEnd = ServiceLocator.getResourceService().getAsset(waveSounds[1], Sound.class);
//this.waveStart = ServiceLocator.getResourceService().getAsset(waveSounds[0], Sound.class);
//this.waveEnd = ServiceLocator.getResourceService().getAsset(waveSounds[1], Sound.class);
}

public void loadSounds() {
Expand Down Expand Up @@ -72,7 +72,7 @@ public void start() {
this.currentWave = level.getWave(currentWaveIndex);
ServiceLocator.getWaveService().setEnemyCount(currentWave.getSize());
logger.info("Wave {} starting with {} enemies", currentWaveIndex, ServiceLocator.getWaveService().getEnemyCount());
this.waveStart.play();
//this.waveStart.play();
//endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000);
}

Expand All @@ -89,6 +89,7 @@ public void update() {
this.waveInProgress = true;
logger.info("No enemies remaining, begin next wave");
currentWaveIndex++;
this.level.setWaveIndex(currentWaveIndex);
this.currentWave = this.level.getWave(currentWaveIndex);
ServiceLocator.getWaveService().setEnemyCount(currentWave.getSize());
//endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000L); // reset end time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class WaveFactory {
*/
public static Entity createWaves() {
HashMap<String, Integer> mobs = new HashMap<>();
mobs.put("Xeno", 0);
mobs.put("Xeno", 3);
mobs.put("DodgingDragon", 4);
HashMap<String, Integer> mobs2 = new HashMap<>();
mobs2.put("Xeno", 3);
WaveClass wave1 = new WaveClass(mobs);
Expand Down

0 comments on commit a963180

Please sign in to comment.