Skip to content

Commit

Permalink
Fixed issues with mob not stopping when moving
Browse files Browse the repository at this point in the history
  • Loading branch information
meganroxburgh committed Sep 9, 2023
1 parent 64d0d13 commit da3b804
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
public class MobAttackTask extends DefaultTask implements PriorityTask {
private static final int INTERVAL = 1; // time interval to scan for towers in
private static final short TARGET = PhysicsLayer.HUMANS; // mobs detecting for towers
// ^ fix this

private static final String STOW = "stowStart";
private static final String DEPLOY = "deployStart";
Expand Down Expand Up @@ -70,7 +71,7 @@ public void start() {
this.maxRangePosition.set(4, mobPosition.y);
owner.getEntity().getEvents().trigger(IDLE);
endTime = timeSource.getTime() + (INTERVAL * 500);
owner.getEntity().getEvents().trigger("shootStart");
// owner.getEntity().getEvents().trigger(FIRING);
System.out.println("mob attack started for " + owner.getEntity().getId());
}

Expand All @@ -82,7 +83,7 @@ public void start() {
public void update() {
updateMobState();

if (mobState == STATE.IDLE) {
if (mobState == STATE.STOW) {
status = Status.FINISHED;
}
}
Expand All @@ -105,9 +106,8 @@ public void updateMobState() {
case IDLE -> {
if (isTargetVisible()) {
// targets detected in idle mode - start deployment
//owner.getEntity().getEvents().trigger(DEPLOY);
mobState = STATE.FIRING;
owner.getEntity().getEvents().trigger(FIRING);
owner.getEntity().getEvents().trigger(DEPLOY);
mobState = STATE.DEPLOY;
}
System.out.println("idle for " + owner.getEntity().getId());

Expand All @@ -132,14 +132,14 @@ public void updateMobState() {
// owner.getEntity().getComponent(PhysicsMovementComponent.class).setEnabled(false);
// targets gone - stop firing
if (!isTargetVisible()) {
//owner.getEntity().getEvents().trigger(STOW);
mobState = STATE.IDLE;
owner.getEntity().getEvents().trigger(STOW);
mobState = STATE.STOW;
} else {
owner.getEntity().getEvents().trigger(FIRING);
Entity newProjectile = ProjectileFactory.createMobBall(TARGET, new Vector2(0, owner.getEntity().getPosition().y), new Vector2(2f,2f));
newProjectile.setPosition((float) (owner.getEntity().getPosition().x - 1), (float) (owner.getEntity().getPosition().y));
newProjectile.setPosition((float) (owner.getEntity().getPosition().x - 0.5), (float) (owner.getEntity().getPosition().y));
ServiceLocator.getEntityService().register(newProjectile);
owner.getEntity().getEvents().trigger(FIRING);
mobState = STATE.STOW;
}
System.out.println("firing for " + owner.getEntity().getId());
owner.getEntity().getComponent(PhysicsMovementComponent.class).setEnabled(true);
Expand Down Expand Up @@ -196,11 +196,11 @@ public int getPriority() {
* @return (int) active priority if a target is visible, -1 otherwise
*/
private int getActivePriority() {
if ((startTime + delay) < timeSource.getTime() && isTargetVisible()) {
if ((startTime + delay) < timeSource.getTime() && isTargetVisible()) {
// if (isTargetVisible() && (startTime + delay) > timeSource.getTime()) {
// System.out.println("ready to fire while active");
return priority;
}
return priority;
}
// System.out.println("not ready to fire while active");
// return !isTargetVisible() ? -1 : priority;
return -1;
Expand Down

0 comments on commit da3b804

Please sign in to comment.