From 72c1ca409cada9d94c1de2911844135cd3fa9e44 Mon Sep 17 00:00:00 2001 From: BlairCannon97 Date: Sun, 10 Sep 2023 12:24:03 +1000 Subject: [PATCH] Changed the hitbox properties of the NPC entities to suit the Xeno --- .../game/components/tasks/MobAttackTask.java | 22 +++++++++---------- .../game/entities/factories/NPCFactory.java | 7 +++--- .../csse3200/game/physics/PhysicsLayer.java | 1 + .../csse3200/game/physics/PhysicsUtils.java | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobAttackTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobAttackTask.java index 4a1b808f9..aff533638 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobAttackTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobAttackTask.java @@ -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"; @@ -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"); } /** @@ -104,7 +103,7 @@ 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; } } @@ -112,10 +111,10 @@ public void updateMobState() { 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; } } @@ -123,15 +122,16 @@ public void updateMobState() { 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; } } @@ -139,10 +139,10 @@ public void updateMobState() { 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; } } 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 ef50acb70..31485fe72 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 @@ -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; @@ -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; } diff --git a/source/core/src/main/com/csse3200/game/physics/PhysicsLayer.java b/source/core/src/main/com/csse3200/game/physics/PhysicsLayer.java index 73c5904aa..b91b9bfcc 100644 --- a/source/core/src/main/com/csse3200/game/physics/PhysicsLayer.java +++ b/source/core/src/main/com/csse3200/game/physics/PhysicsLayer.java @@ -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; diff --git a/source/core/src/main/com/csse3200/game/physics/PhysicsUtils.java b/source/core/src/main/com/csse3200/game/physics/PhysicsUtils.java index 44936b077..168065d1b 100644 --- a/source/core/src/main/com/csse3200/game/physics/PhysicsUtils.java +++ b/source/core/src/main/com/csse3200/game/physics/PhysicsUtils.java @@ -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() {