Add sound and animation to enemy death
This commit is contained in:
@@ -25,6 +25,8 @@ public class EnemyDAO {
|
||||
.animationSpeed(result.getFloat("animation_speed"))
|
||||
.blocking(result.getBoolean("blocking"))
|
||||
.meleeWeapon(result.getString("melee_weapon"))
|
||||
.dieAnimation(result.getString("die_animation"))
|
||||
.dieSound(result.getString("die_sound"))
|
||||
.build();
|
||||
enemies.put(result.getString("id"), enemy);
|
||||
}
|
||||
|
||||
@@ -14,4 +14,6 @@ public class EnemyModel {
|
||||
private final float animationSpeed;
|
||||
private final boolean blocking;
|
||||
private final String meleeWeapon;
|
||||
private final String dieAnimation;
|
||||
private final String dieSound;
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.bartlomiejpluta.base.api.ai.NPC;
|
||||
import com.bartlomiejpluta.base.api.move.MoveEvent;
|
||||
|
||||
import com.bartlomiejpluta.base.lib.ai.NoopAI;
|
||||
import com.bartlomiejpluta.base.lib.animation.*;
|
||||
|
||||
import com.bartlomiejpluta.demo.runner.DemoRunner;
|
||||
import com.bartlomiejpluta.demo.database.model.EnemyModel;
|
||||
@@ -20,6 +21,7 @@ import com.bartlomiejpluta.demo.ai.*;
|
||||
public class Enemy extends Character implements NPC {
|
||||
private final EnemyModel template;
|
||||
private AI ai = NoopAI.INSTANCE;
|
||||
private final AnimationRunner dieAnimation;
|
||||
|
||||
public Enemy(@NonNull Context context, @NonNull EnemyModel template) {
|
||||
super(context, context.createEntity(template.getEntitySet()));
|
||||
@@ -29,6 +31,7 @@ public class Enemy extends Character implements NPC {
|
||||
setAnimationSpeed(template.getAnimationSpeed());
|
||||
setBlocking(template.isBlocking());
|
||||
setWeapon(new MeleeWeapon(context, ((DemoRunner) context.getGameRunner()).getMeleeWeaponDAO().get(template.getMeleeWeapon())));
|
||||
this.dieAnimation = new SimpleAnimationRunner(template.getDieAnimation());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,6 +50,8 @@ public class Enemy extends Character implements NPC {
|
||||
ai = NoopAI.INSTANCE;
|
||||
|
||||
getLayer().handleEvent(new EnemyDiedEvent(this));
|
||||
dieAnimation.run(context, getLayer(), this);
|
||||
context.playSound(template.getDieSound());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user