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 8bfe9b562..ca39f9218 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -139,6 +139,7 @@ public void create() { spawnBuilding2(); spawnMountains(); player = spawnPlayer(); + player.getEvents().addListener("spawnWave", this::spawnXenoGrunts); playMusic(); @@ -312,6 +313,7 @@ private void spawnProjectile(Vector2 position, Entity target, int space, int di // } + private void spawnXenoGrunts() { GridPoint2 minPos = terrain.getMapBounds(0).sub(1, 5); GridPoint2 maxPos = terrain.getMapBounds(0).sub(1, 25); diff --git a/source/core/src/main/com/csse3200/game/components/tasks/SpawnWaveTask.java b/source/core/src/main/com/csse3200/game/components/tasks/SpawnWaveTask.java new file mode 100644 index 000000000..cb326b8b4 --- /dev/null +++ b/source/core/src/main/com/csse3200/game/components/tasks/SpawnWaveTask.java @@ -0,0 +1,41 @@ +package com.csse3200.game.components.tasks; + +import com.badlogic.gdx.math.Vector2; +import com.csse3200.game.ai.tasks.DefaultTask; +import com.csse3200.game.ai.tasks.PriorityTask; +import com.csse3200.game.ai.tasks.Task; +import com.csse3200.game.services.GameTime; +import com.csse3200.game.services.ServiceLocator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SpawnWaveTask extends DefaultTask implements PriorityTask { + private static final Logger logger = LoggerFactory.getLogger(SpawnWaveTask.class); + private final GameTime globalTime; + private long endTime; + + private final int SPAWNING_INTERVAL = 10; + + public SpawnWaveTask() { + this.globalTime = ServiceLocator.getTimeSource(); + } + + @Override + public int getPriority() { + return 10; // Low priority task + } + + @Override + public void start() { + super.start(); + endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000); + } + + @Override + public void update() { + if (globalTime.getTime() >= endTime) { + this.owner.getEntity().getEvents().trigger("spawnWave"); + endTime = globalTime.getTime() + (SPAWNING_INTERVAL * 1000L); // reset end time + } + } +} diff --git a/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java index f92cb8dec..ba6eb927e 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java @@ -9,6 +9,7 @@ import com.csse3200.game.components.npc.XenoAnimationController; import com.csse3200.game.components.TouchAttackComponent; import com.csse3200.game.components.tasks.MobAttackTask; +import com.csse3200.game.components.tasks.SpawnWaveTask; import com.csse3200.game.components.tasks.WanderTask; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.Melee; diff --git a/source/core/src/main/com/csse3200/game/entities/factories/PlayerFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/PlayerFactory.java index 6a407c950..a76b2a6ca 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/PlayerFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/PlayerFactory.java @@ -1,9 +1,14 @@ package com.csse3200.game.entities.factories; +import com.badlogic.gdx.math.Vector2; +import com.csse3200.game.ai.tasks.AITaskComponent; import com.csse3200.game.components.CombatStatsComponent; import com.csse3200.game.components.player.InventoryComponent; import com.csse3200.game.components.player.PlayerActions; import com.csse3200.game.components.player.PlayerStatsDisplay; +import com.csse3200.game.components.tasks.MobAttackTask; +import com.csse3200.game.components.tasks.SpawnWaveTask; +import com.csse3200.game.components.tasks.WanderTask; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.configs.PlayerConfig; import com.csse3200.game.files.FileLoader; @@ -33,7 +38,9 @@ public class PlayerFactory { public static Entity createPlayer() { InputComponent inputComponent = ServiceLocator.getInputService().getInputFactory().createForPlayer(); - + AITaskComponent aiComponent = + new AITaskComponent() + .addTask(new SpawnWaveTask()); Entity player = new Entity() .addComponent(new TextureRenderComponent("images/box_boy_leaf.png")) @@ -44,6 +51,7 @@ public static Entity createPlayer() { .addComponent(new CombatStatsComponent(stats.health, stats.baseAttack)) .addComponent(new InventoryComponent(stats.gold)) .addComponent(inputComponent) + .addComponent(aiComponent) .addComponent(new PlayerStatsDisplay()); PhysicsUtils.setScaledCollider(player, 0.6f, 0.3f);