From 078f7161e8a92f988e5af35a22a69a7b14b54702 Mon Sep 17 00:00:00 2001 From: gregchan550 <86044792+gregchan550@users.noreply.github.com> Date: Wed, 20 Sep 2023 22:21:40 +1000 Subject: [PATCH] fixed bug where cleave() was randomly going off because a getNearbyHumans wasn't checking for humans properly --- .../components/tasks/bosstask/DemonBossTask.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java b/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java index cf52404b8..bfd5b0ff2 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java @@ -129,7 +129,10 @@ public void update() { case SMASH -> { if (jumpComplete()) { if (getNearbyHumans().isEmpty()) { fireBreath(); } - else { cleave(); } + else { + System.out.println(getNearbyHumans()); + cleave(); + } } } case BREATH -> { @@ -203,22 +206,23 @@ public int getPriority() { } private Array getNearbyHumans() { - Array nearbyHumans = ServiceLocator.getEntityService(). + Array nearbyEntities = ServiceLocator.getEntityService(). getNearbyEntities(demon, SMASH_RADIUS); - for (int i = 0; i < nearbyHumans.size; i++) { - Entity targetEntity = nearbyHumans.get(i); + Array nearbyHumans = new Array<>(); + for (int i = 0; i < nearbyEntities.size; i++) { + Entity targetEntity = nearbyEntities.get(i); HitboxComponent targetHitbox = targetEntity.getComponent(HitboxComponent.class); if (targetHitbox == null) { break; } // target layer check if (!PhysicsLayer.contains(PhysicsLayer.HUMANS, targetHitbox. getLayer())) { break; } + nearbyHumans.add(targetEntity); } return nearbyHumans; } private void jump(Vector2 finalPos) { - System.out.println(finalPos); changeState(DemonState.SMASH); isJumping = true;