Skip to content

Commit

Permalink
Changed the hitbox properties of the NPC entities to suit the Xeno
Browse files Browse the repository at this point in the history
  • Loading branch information
BlairCannon97 committed Sep 10, 2023
1 parent 4d3ab82 commit 72c1ca4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MobAttackTask extends DefaultTask implements PriorityTask {
private static final short TARGET = PhysicsLayer.OBSTACLE; // mobs detecting for towers
// ^ fix this

private static final String STOW = "stowStart";
private static final String STOW = "wanderStart";
private static final String DEPLOY = "deployStart";
private static final String FIRING = "shootStart";
private static final String IDLE = "idleStart";
Expand Down Expand Up @@ -68,9 +68,8 @@ public void start() {
startTime = timeSource.getTime();
this.mobPosition = owner.getEntity().getCenterPosition();
this.maxRangePosition.set(0, mobPosition.y);
owner.getEntity().getEvents().trigger(IDLE);
//owner.getEntity().getEvents().trigger(IDLE);
endTime = timeSource.getTime() + (INTERVAL * 500);
owner.getEntity().getEvents().trigger("shootStart");
}

/**
Expand Down Expand Up @@ -104,45 +103,46 @@ public void updateMobState() {
case IDLE -> {
if (isTargetVisible()) {
// targets detected in idle mode - start deployment
owner.getEntity().getEvents().trigger(DEPLOY);
//owner.getEntity().getEvents().trigger(DEPLOY);
mobState = STATE.DEPLOY;
}
}

case DEPLOY -> {
// currently deploying,
if (isTargetVisible()) {
owner.getEntity().getEvents().trigger(FIRING);
//owner.getEntity().getEvents().trigger(FIRING);
mobState = STATE.FIRING;
} else {
owner.getEntity().getEvents().trigger(STOW);
//owner.getEntity().getEvents().trigger(STOW);
mobState = STATE.STOW;
}
}

case FIRING -> {
// targets gone - stop firing
if (!isTargetVisible()) {
owner.getEntity().getEvents().trigger(STOW);
//owner.getEntity().getEvents().trigger(STOW);
mobState = STATE.STOW;
} else {
System.out.printf("ANIMATION: " + owner.getEntity().getComponent(AnimationRenderComponent.class).getCurrentAnimation() + "\n");
owner.getEntity().getEvents().trigger(FIRING);
Entity newProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0, owner.getEntity().getPosition().y), new Vector2(2f,2f));
newProjectile.setPosition((float) (owner.getEntity().getPosition().x), (float) (owner.getEntity().getPosition().y));
newProjectile.setScale(-1f, 0.5f);
ServiceLocator.getEntityService().register(newProjectile);

System.out.printf("ANIMATION: " + owner.getEntity().getComponent(AnimationRenderComponent.class).getCurrentAnimation() + "\n");
owner.getEntity().getEvents().trigger(FIRING);
mobState = STATE.STOW;
}
}

case STOW -> {
// currently stowing
if (isTargetVisible()) {
owner.getEntity().getEvents().trigger(DEPLOY);
//owner.getEntity().getEvents().trigger(DEPLOY);
mobState = STATE.DEPLOY;
} else {
owner.getEntity().getEvents().trigger(IDLE);
//owner.getEntity().getEvents().trigger(IDLE);
mobState = STATE.IDLE;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public static Entity createXenoGrunt(Entity target) {
.addComponent(animator)
.addComponent(new XenoAnimationController());

xenoGrunt.getComponent(HitboxComponent.class).setAsBoxAligned(new Vector2(.3f, .5f), PhysicsComponent.AlignX.RIGHT, PhysicsComponent.AlignY.BOTTOM);
xenoGrunt.getComponent(AnimationRenderComponent.class).scaleEntity();

return xenoGrunt;
Expand All @@ -149,11 +150,11 @@ public static Entity createBaseNPC(Entity target) {
.addComponent(new PhysicsComponent())
.addComponent(new PhysicsMovementComponent())
.addComponent(new ColliderComponent())
.addComponent(new HitboxComponent().setLayer(PhysicsLayer.NPC))
.addComponent(new TouchAttackComponent(PhysicsLayer.HUMANS, 1.5f))
.addComponent(new HitboxComponent().setLayer(PhysicsLayer.XENO))
.addComponent(new TouchAttackComponent(PhysicsLayer.HUMANS))
.addComponent(aiComponent);

PhysicsUtils.setScaledCollider(npc, 0.9f, 0.4f);
PhysicsUtils.setScaledCollider(npc, 0.3f, 0.5f);
return npc;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class PhysicsLayer {
public static final short PROJECTILE = (1 << 4);
public static final short TOWER = (1 << 5);

public static final short XENO = (1 << 3);
public static final short HUMANS = (1 << 1) | (1 << 5);
public static final short ALL = ~0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void setScaledCollider(Entity entity, float scaleX, float scaleY)
entity
.getComponent(ColliderComponent.class)
.setAsBoxAligned(
boundingBox, PhysicsComponent.AlignX.CENTER, PhysicsComponent.AlignY.BOTTOM);
boundingBox, PhysicsComponent.AlignX.RIGHT, PhysicsComponent.AlignY.BOTTOM);
}

private PhysicsUtils() {
Expand Down

0 comments on commit 72c1ca4

Please sign in to comment.