Skip to content

Commit

Permalink
update changes
Browse files Browse the repository at this point in the history
  • Loading branch information
The-AhmadAA committed Sep 6, 2023
1 parent d5dd3d4 commit 4ff5b0a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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");
Expand All @@ -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
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
}

Expand All @@ -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();
Expand Down Expand Up @@ -89,7 +90,7 @@ private void startWaiting() {

private void startMoving() {
logger.debug("Starting moving");
movementTask.setTarget(getDirection());
movementTask.setTarget(this.wanderRange);
swapTask(movementTask);
}

Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 4ff5b0a

Please sign in to comment.