Skip to content

Commit

Permalink
fixed bug where mobs werent dying properly
Browse files Browse the repository at this point in the history
  • Loading branch information
gregchan550 committed Oct 9, 2023
1 parent d1be527 commit 520e5eb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,12 @@ public void create() {
// waves = WaveFactory.createWaves();
// spawnEntity(waves);
// waves.getEvents().addListener("spawnWave", this::spawnMob);
// spawnGregMob();
spawnGregMob();
// spawnDodgingDragonKnight(17,4);
// spawnDeflectWizard(17, 3);
// spawnSplittingXenoGrunt(17, 2);
// spawnPatrick();
spawnDemonBoss();
// spawnDemonBoss();

spawnScrap();
spawnGapScanners();
Expand Down Expand Up @@ -728,7 +728,7 @@ private void spawnDeflectWizard(int x, int y) {
// }

private void spawnGregMob() {
Entity gregMob = NPCFactory.createGregMeleeMob(100);
Entity gregMob = NPCFactory.createBaseWaterSlime(100);
gregMob.setScale(1.5f, 1.5f);
spawnEntityAt(gregMob, new GridPoint2(17, 4), false, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ public class MobTask extends DefaultTask implements PriorityTask {

// Constants
private static final int PRIORITY = 3;
private static final Vector2 MELEE_MOB_SPEED = new Vector2(1f,1f);
private static final Vector2 MELEE_RANGE_SPEED = new Vector2(0.7f,0.7f);
private static final Vector2 MELEE_MOB_SPEED = new Vector2(0.7f,0.7f);
private static final Vector2 MELEE_RANGE_SPEED = new Vector2(0.5f,0.5f);
private static final int MELEE_DAMAGE = 10;
private static final long MELEE_ATTACK_SPEED = 2000;
private static final long RANGE_ATTACK_SPEED = 5000;
private static final int MELEE_ATTACK_RANGE = 1;

// Private variables
private final MobType mobType;
Expand Down Expand Up @@ -98,8 +99,13 @@ public void start() {
public void update() {

// death check
if (mob.getComponent(CombatStatsComponent.class).getHealth() <= 0) {
if (mob.getComponent(CombatStatsComponent.class).getHealth() <= 0 && !deathFlag) {
changeState(State.DEATH);
animate();
movementTask.stop();
deathFlag = true;
} else if (deathFlag && animation.isFinished()) {
mob.setFlagForDelete(true);
}

switch (state) {
Expand Down Expand Up @@ -151,15 +157,6 @@ public void update() {
}
}
}
case DEATH -> {
if (deathFlag) {
animate();
deathFlag = false;
}
if (animation.isFinished() && !deathFlag) {
mob.setFlagForDelete(true);
}
}
}
}

Expand Down Expand Up @@ -196,7 +193,10 @@ private void animate() {
switch (state) {
case RUN -> owner.getEntity().getEvents().trigger("water_slime_walk");
case ATTACK -> owner.getEntity().getEvents().trigger("water_slime_attack");
case DEATH -> owner.getEntity().getEvents().trigger("water_slime_death");
case DEATH -> {
System.out.println("hi");
owner.getEntity().getEvents().trigger("water_slime_death");
}
case DEFAULT -> owner.getEntity().getEvents().trigger("default");
}
}
Expand Down Expand Up @@ -235,7 +235,7 @@ private void changeState(State state) {
private boolean enemyDetected() {
// if there's an entity within x of - 1 of mob
Entity target = ServiceLocator.getEntityService().getEntityAtPosition(
mob.getPosition().x - 1, mob.getPosition().y);
mob.getPosition().x - MELEE_ATTACK_RANGE, mob.getPosition().y);
if (target == null) {
return false;
}
Expand Down

0 comments on commit 520e5eb

Please sign in to comment.