Skip to content

Commit

Permalink
fixed demon boss inability to sense nearby towers
Browse files Browse the repository at this point in the history
  • Loading branch information
gregchan550 committed Oct 11, 2023
1 parent 3887a2c commit 2897788
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ public void create() {
// Set up infrastructure for end game tracking
player = spawnPlayer();

waves = WaveFactory.createWaves();
spawnEntity(waves);
waves.getEvents().addListener("spawnWave", this::spawnMob);
// waves = WaveFactory.createWaves();
// spawnEntity(waves);
// waves.getEvents().addListener("spawnWave", this::spawnMob);
// spawnGregMob(18, 2);
// spawnDemonBoss();
spawnDemonBoss();
// spawnEffectProjectile(new Vector2(10f,2f), PhysicsLayer.NPC, 20, new Vector2(2f,2f), ProjectileEffects.SLOW, false);

spawnScrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class DemonBossTask extends DefaultTask implements PriorityTask {
private static int xLeftBoundary = 12;
private ProjectileEffects effect = ProjectileEffects.BURN;
private boolean aoe = true;
private Array<Entity> nearbyEntities;

// Flags
private boolean startFlag = false;
Expand Down Expand Up @@ -167,11 +168,10 @@ public void update() {
case IDLE -> jump(getJumpPos());
case SMASH -> {
if (jumpComplete()) {
if (getNearbyHumans(SMASH_RADIUS).isEmpty()) {
fireBreath();
}
else {
if (nearbyEntities != null && !nearbyEntities.isEmpty()) {
cleave();
} else {
fireBreath();
}
}
}
Expand Down Expand Up @@ -247,34 +247,34 @@ public int getPriority() {
return PRIORITY;
}

/**
* Returns a list of nearby entities with PhysicsLayer.HUMAN.
*
* @return nearby entities with the PhysicsLayer of HUMAN
*/
private Array<Entity> getNearbyHumans(int radius) {
Array<Entity> nearbyEntities = ServiceLocator.getEntityService().
getNearbyEntities(demon, radius);
Array<Entity> nearbyHumans = new Array<>();

// iterate through nearby entities checking if they have desired properties
for (int i = 0; i < nearbyEntities.size; i++) {
Entity targetEntity = nearbyEntities.get(i);
HitboxComponent targetHitbox = targetEntity.getComponent(HitboxComponent.class);
if (targetHitbox == null) {
break;
}

// check target layer
if (!PhysicsLayer.contains(PhysicsLayer.HUMANS, targetHitbox.
getLayer())) {
break;
}

nearbyHumans.add(targetEntity);
}
return nearbyHumans;
}
// /**
// * Returns a list of nearby entities with PhysicsLayer.HUMAN.
// *
// * @return nearby entities with the PhysicsLayer of HUMAN
// */
// private Array<Entity> getNearbyHumans(int radius) {
// Array<Entity> nearbyEntities = ServiceLocator.getEntityService().
// getNearbyEntities(demon, radius);
// Array<Entity> nearbyHumans = new Array<>();
//
// // iterate through nearby entities checking if they have desired properties
// for (int i = 0; i < nearbyEntities.size; i++) {
// Entity targetEntity = nearbyEntities.get(i);
// HitboxComponent targetHitbox = targetEntity.getComponent(HitboxComponent.class);
// if (targetHitbox == null) {
// break;
// }
//
// // check target layer
// if (!PhysicsLayer.contains(PhysicsLayer.HUMANS, targetHitbox.
// getLayer())) {
// break;
// }
//
// nearbyHumans.add(targetEntity);
// }
// return nearbyHumans;
// }

/**
* Changes state of demon and moves it to the desired position.
Expand Down Expand Up @@ -346,7 +346,9 @@ private Vector2 getJumpPos() {
*/
private boolean jumpComplete() {
if (animation.isFinished() && isJumping) {
applyAoeDamage(getNearbyHumans(SMASH_RADIUS), SMASH_DAMAGE); // do damage upon landing
nearbyEntities = ServiceLocator.getEntityService().getEntitiesInLayer(
demon, SMASH_RADIUS, PhysicsLayer.HUMANS);
applyAoeDamage(nearbyEntities, SMASH_DAMAGE); // do damage upon landing
isJumping = false;
jumpTask.stop();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ public static Entity createBaseBoss() {
.addComponent(new TouchAttackComponent(PhysicsLayer.HUMANS, 1.5f));

// PhysicsUtils.setScaledCollider(boss, 0.9f, 0.4f);

return boss;
}

Expand Down

0 comments on commit 2897788

Please sign in to comment.