From a9631806ea9957fb1b49fca0fa81a4d746f7aba1 Mon Sep 17 00:00:00 2001 From: bojyyy <140468434+bojyyy@users.noreply.github.com> Date: Thu, 28 Sep 2023 18:18:05 +1000 Subject: [PATCH] Fixes bugs in wave functionality and allows for different mob types --- .../csse3200/game/areas/ForestGameArea.java | 47 +++++++++++++------ .../game/components/tasks/MobWanderTask.java | 3 +- .../components/tasks/NewMobWanderTask.java | 1 + .../components/tasks/waves/LevelWaves.java | 6 ++- .../game/components/tasks/waves/WaveTask.java | 7 +-- .../game/entities/factories/WaveFactory.java | 3 +- 6 files changed, 45 insertions(+), 22 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index a7213d7bf..8cb1d4d72 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -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. @@ -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(); @@ -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 diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobWanderTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobWanderTask.java index 577983d5a..99d37afdc 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobWanderTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobWanderTask.java @@ -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 @@ -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); } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/NewMobWanderTask.java b/source/core/src/main/com/csse3200/game/components/tasks/NewMobWanderTask.java index 2a6291e66..f8a196a50 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/NewMobWanderTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/NewMobWanderTask.java @@ -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); diff --git a/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java b/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java index d68d1c12f..b4c357093 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/waves/LevelWaves.java @@ -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); @@ -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; + } } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java b/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java index 95f29811b..76679c2cc 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/waves/WaveTask.java @@ -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() { @@ -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); } @@ -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 diff --git a/source/core/src/main/com/csse3200/game/entities/factories/WaveFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/WaveFactory.java index d3cbb3094..5c4cbca9c 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/WaveFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/WaveFactory.java @@ -16,7 +16,8 @@ public class WaveFactory { */ public static Entity createWaves() { HashMap mobs = new HashMap<>(); - mobs.put("Xeno", 0); + mobs.put("Xeno", 3); + mobs.put("DodgingDragon", 4); HashMap mobs2 = new HashMap<>(); mobs2.put("Xeno", 3); WaveClass wave1 = new WaveClass(mobs);