Make all characters (including player and enemies) mortal
This commit is contained in:
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
BIN
entsets/9da2c95b-45b7-49e5-957b-c1c8803cdf28.png
Normal file
BIN
entsets/9da2c95b-45b7-49e5-957b-c1c8803cdf28.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
@@ -3,7 +3,8 @@
|
||||
$f845355e-b9ad-4884-a217-dd3a4c18a3fa(f845355e-b9ad-4884-a217-dd3a4c18a3fa.datForrest Temple"d
|
||||
$d314b030-f865-432e-a356-3845f8aac7bc(d314b030-f865-432e-a356-3845f8aac7bc.pngForrest Temple ](2Z
|
||||
$815a5c5c-4979-42f5-a42a-ccbbff9a97e5(815a5c5c-4979-42f5-a42a-ccbbff9a97e5.pngLuna (2Z
|
||||
$cb4c89a7-a421-49ea-8c58-571e9b215d37(cb4c89a7-a421-49ea-8c58-571e9b215d37.pngDeku (:`
|
||||
$cb4c89a7-a421-49ea-8c58-571e9b215d37(cb4c89a7-a421-49ea-8c58-571e9b215d37.pngDeku (2\
|
||||
$9da2c95b-45b7-49e5-957b-c1c8803cdf28(9da2c95b-45b7-49e5-957b-c1c8803cdf28.pngCorpse (:`
|
||||
$2261c04f-b02e-4486-b388-8a0fa41622e9(2261c04f-b02e-4486-b388-8a0fa41622e9.ttfRoboto RegularB\
|
||||
$ab9d40b4-eb28-45d7-bff2-9432a05eb41a(ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml
|
||||
Start MenuB[
|
||||
|
||||
@@ -19,6 +19,8 @@ public class EnemyDAO {
|
||||
.id(result.getString("id"))
|
||||
.name(result.getString("name"))
|
||||
.entitySet(result.getString("entset"))
|
||||
.deadEntitySet(result.getString("dead_entset"))
|
||||
.hp(result.getInt("hp"))
|
||||
.speed(result.getFloat("speed"))
|
||||
.animationSpeed(result.getFloat("animation_speed"))
|
||||
.blocking(result.getBoolean("blocking"))
|
||||
|
||||
@@ -8,6 +8,8 @@ public class EnemyModel {
|
||||
private final String id;
|
||||
private final String name;
|
||||
private final String entitySet;
|
||||
private final String deadEntitySet;
|
||||
private final int hp;
|
||||
private final float speed;
|
||||
private final float animationSpeed;
|
||||
private final boolean blocking;
|
||||
|
||||
@@ -7,19 +7,32 @@ import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||
import com.bartlomiejpluta.base.lib.entity.EntityDelegate;
|
||||
|
||||
import com.bartlomiejpluta.demo.runner.DemoRunner;
|
||||
import com.bartlomiejpluta.demo.world.weapon.MeleeWeapon;
|
||||
|
||||
public class Character extends EntityDelegate {
|
||||
private static final Logger log = LoggerFactory.getLogger(Character.class);
|
||||
protected final Context context;
|
||||
protected final DemoRunner runner;
|
||||
|
||||
protected int attackCooldown = 0;
|
||||
|
||||
@Getter
|
||||
protected boolean alive = true;
|
||||
|
||||
@Getter
|
||||
protected boolean immortal = false;
|
||||
|
||||
@Getter
|
||||
protected int hp;
|
||||
|
||||
@Setter
|
||||
private MeleeWeapon weapon;
|
||||
|
||||
|
||||
public Character(@NonNull Context context, @NonNull Entity entity) {
|
||||
super(entity);
|
||||
this.context = context;
|
||||
this.runner = (DemoRunner) context.getGameRunner();
|
||||
}
|
||||
|
||||
public void attack() {
|
||||
@@ -39,7 +52,12 @@ public class Character extends EntityDelegate {
|
||||
}
|
||||
|
||||
public void hit(int dmg) {
|
||||
if(immortal) {
|
||||
return;
|
||||
}
|
||||
|
||||
log.info(toString() + " received " + dmg + " damage");
|
||||
hp -= dmg;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,5 +67,14 @@ public class Character extends EntityDelegate {
|
||||
if(weapon != null && attackCooldown < weapon.getCooldown()) {
|
||||
attackCooldown += (int) (dt * 1000f);
|
||||
}
|
||||
|
||||
if(hp <= 0 && alive && getLayer() != null) {
|
||||
alive = false;
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
protected void die() {
|
||||
log.info(toString() + " died with HP = " + hp);
|
||||
}
|
||||
}
|
||||
@@ -15,10 +15,12 @@ import com.bartlomiejpluta.demo.world.weapon.MeleeWeapon;
|
||||
|
||||
public class Enemy extends Character implements NPC {
|
||||
private final EnemyModel template;
|
||||
private AI ai = NoopAI.INSTANCE;
|
||||
|
||||
public Enemy(@NonNull Context context, @NonNull EnemyModel template) {
|
||||
super(context, context.createEntity(template.getEntitySet()));
|
||||
this.template = template;
|
||||
hp = template.getHp();
|
||||
setSpeed(template.getSpeed());
|
||||
setAnimationSpeed(template.getAnimationSpeed());
|
||||
setBlocking(template.isBlocking());
|
||||
@@ -27,7 +29,18 @@ public class Enemy extends Character implements NPC {
|
||||
|
||||
@Override
|
||||
public AI getStrategy() {
|
||||
return NoopAI.INSTANCE;
|
||||
return ai;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void die() {
|
||||
super.die();
|
||||
changeEntitySet(template.getDeadEntitySet());
|
||||
setScale(0.5f);
|
||||
setBlocking(false);
|
||||
setZIndex(-1);
|
||||
|
||||
ai = NoopAI.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
package com.bartlomiejpluta.demo.entity;
|
||||
|
||||
import lombok.*;
|
||||
import org.slf4j.*;
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||
|
||||
public class Player extends Character {
|
||||
private static final Logger log = LoggerFactory.getLogger(Player.class);
|
||||
|
||||
public Player(@NonNull Context context, @NonNull Entity entity) {
|
||||
super(context, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void die() {
|
||||
super.die();
|
||||
runner.returnToStartMenu();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user