Skip to content

Commit

Permalink
fixed bug where cleave() was randomly going off because a getNearbyHu…
Browse files Browse the repository at this point in the history
…mans wasn't checking for humans properly
  • Loading branch information
gregchan550 committed Sep 20, 2023
1 parent be35ccc commit 078f716
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down Expand Up @@ -203,22 +206,23 @@ public int getPriority() {
}

private Array<Entity> getNearbyHumans() {
Array<Entity> nearbyHumans = ServiceLocator.getEntityService().
Array<Entity> nearbyEntities = ServiceLocator.getEntityService().
getNearbyEntities(demon, SMASH_RADIUS);
for (int i = 0; i < nearbyHumans.size; i++) {
Entity targetEntity = nearbyHumans.get(i);
Array<Entity> 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;

Expand Down

0 comments on commit 078f716

Please sign in to comment.