From 4ff5b0a711e1f94cdef770ff670946668ccc17a2 Mon Sep 17 00:00:00 2001 From: Ahmad Abu-Aysha Date: Wed, 6 Sep 2023 15:12:25 +1000 Subject: [PATCH] update changes --- .../com/csse3200/game/areas/ForestGameArea.java | 2 +- .../tasks/human/HumanMovementTask.java | 17 +++++++++-------- .../components/tasks/human/HumanWanderTask.java | 16 +++++++++------- .../entities/factories/EngineerFactory.java | 9 +++++---- 4 files changed, 24 insertions(+), 20 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 a209f79bf..2db29b800 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -155,7 +155,7 @@ public void create() { bossKing1 = spawnBossKing1(); bossKing2 = spawnBossKing2(); - Entity engineer = EngineerFactory.createEngineer(); + Entity engineer = EngineerFactory.createEngineer(player); spawnEntityAt(engineer, new GridPoint2(5, 20), true, true); playMusic(); diff --git a/source/core/src/main/com/csse3200/game/components/tasks/human/HumanMovementTask.java b/source/core/src/main/com/csse3200/game/components/tasks/human/HumanMovementTask.java index 7b64f1fc7..00ed0d673 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/human/HumanMovementTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/human/HumanMovementTask.java @@ -2,6 +2,7 @@ import com.badlogic.gdx.math.Vector2; import com.csse3200.game.ai.tasks.DefaultTask; +import com.csse3200.game.entities.Entity; import com.csse3200.game.physics.components.PhysicsMovementComponent; import com.csse3200.game.services.GameTime; import com.csse3200.game.services.ServiceLocator; @@ -16,18 +17,18 @@ public class HumanMovementTask extends DefaultTask { private static final Logger logger = LoggerFactory.getLogger(HumanMovementTask.class); private final GameTime gameTime; - private Vector2 target; + private Entity target; private float stopDistance = 0.01f; private long lastTimeMoved; private Vector2 lastPos; private PhysicsMovementComponent movementComponent; - public HumanMovementTask(Vector2 target) { + public HumanMovementTask(Entity target) { this.target = target; this.gameTime = ServiceLocator.getTimeSource(); } - public HumanMovementTask(Vector2 target, float stopDistance) { + public HumanMovementTask(Entity target, float stopDistance) { this(target); this.stopDistance = stopDistance; } @@ -36,11 +37,11 @@ public HumanMovementTask(Vector2 target, float stopDistance) { public void start() { super.start(); this.movementComponent = owner.getEntity().getComponent(PhysicsMovementComponent.class); - movementComponent.setTarget(target); + movementComponent.setTarget(target.getPosition()); movementComponent.setMoving(true); // Trigger the correct walk animation depending on the target location. - if (target.x < owner.getEntity().getPosition().x) { + if (target.getPosition().x < owner.getEntity().getPosition().x) { owner.getEntity().getEvents().trigger("walkLeftStart"); } else { owner.getEntity().getEvents().trigger("walkRightStart"); @@ -62,9 +63,9 @@ public void update() { } } - public void setTarget(Vector2 target) { + public void setTarget(Entity target) { this.target = target; - movementComponent.setTarget(target); + movementComponent.setTarget(target.getPosition()); } @Override @@ -75,7 +76,7 @@ public void stop() { } private boolean isAtTarget() { - return owner.getEntity().getPosition().dst(target) <= stopDistance; + return owner.getEntity().getPosition().dst(target.getPosition()) <= stopDistance; } private void checkIfStuck() { diff --git a/source/core/src/main/com/csse3200/game/components/tasks/human/HumanWanderTask.java b/source/core/src/main/com/csse3200/game/components/tasks/human/HumanWanderTask.java index 783f5857d..7562da7fc 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/human/HumanWanderTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/human/HumanWanderTask.java @@ -8,6 +8,7 @@ import com.csse3200.game.components.player.HumanCombatStatsComponent; import com.csse3200.game.components.tasks.MovementTask; import com.csse3200.game.components.tasks.WaitTask; +import com.csse3200.game.entities.Entity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,7 +19,7 @@ public class HumanWanderTask extends DefaultTask implements PriorityTask { private static final Logger logger = LoggerFactory.getLogger(HumanWanderTask.class); - private final Vector2 wanderRange; + private final Entity wanderRange; private final float waitTime; private Vector2 startPos; private HumanMovementTask movementTask; @@ -32,8 +33,8 @@ public class HumanWanderTask extends DefaultTask implements PriorityTask { * called. * @param waitTime How long in seconds to wait between wandering. */ - public HumanWanderTask(Vector2 wanderRange, float waitTime) { - this.wanderRange = wanderRange; + public HumanWanderTask(Entity target, float waitTime) { + this.wanderRange = target; this.waitTime = waitTime; } @@ -50,7 +51,7 @@ public void start() { waitTask = new HumanWaitTask(waitTime); waitTask.create(owner); - movementTask = new HumanMovementTask(getDirection()); + movementTask = new HumanMovementTask(this.wanderRange); movementTask.create(owner); movementTask.start(); @@ -89,7 +90,7 @@ private void startWaiting() { private void startMoving() { logger.debug("Starting moving"); - movementTask.setTarget(getDirection()); + movementTask.setTarget(this.wanderRange); swapTask(movementTask); } @@ -102,7 +103,8 @@ private void swapTask(Task newTask) { } private Vector2 getDirection() { - float y = startPos.y; - return new Vector2(0, y); +// float y = startPos.y; +// return new Vector2(0, y); + return this.wanderRange.getPosition(); } } diff --git a/source/core/src/main/com/csse3200/game/entities/factories/EngineerFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/EngineerFactory.java index e61a50edb..1b2e8f138 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/EngineerFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/EngineerFactory.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.math.Vector2; import com.csse3200.game.ai.tasks.AITaskComponent; +import com.csse3200.game.areas.GameArea; import com.csse3200.game.components.CombatStatsComponent; import com.csse3200.game.components.TouchAttackComponent; import com.csse3200.game.components.npc.GhostAnimationController; @@ -57,8 +58,8 @@ public class EngineerFactory { * * @return entity */ - public static Entity createEngineer() { - Entity engineer = createBaseHumanNPC(); + public static Entity createEngineer(Entity target) { + Entity engineer = createBaseHumanNPC(target); BaseEntityConfig config = configs.engineer; AnimationRenderComponent animator = new AnimationRenderComponent( @@ -86,10 +87,10 @@ public static Entity createEngineer() { * * @return entity */ - public static Entity createBaseHumanNPC() { + public static Entity createBaseHumanNPC(Entity target) { AITaskComponent aiComponent = new AITaskComponent() - .addTask(new HumanWanderTask(new Vector2(5, 10f), 2f)); + .addTask(new HumanWanderTask(target, 2f)); Entity human = new Entity()