Apply BASE engine refactor

This commit is contained in:
2022-08-22 22:59:41 +02:00
parent 1253139bfe
commit 933608b753
29 changed files with 99 additions and 99 deletions

View File

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 9.9 KiB

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

View File

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

View File

@@ -2,17 +2,17 @@
BASE Demo*com.bartlomiejpluta.demo.runner.DemoRunner` BASE Demo*com.bartlomiejpluta.demo.runner.DemoRunner`
$f845355e-b9ad-4884-a217-dd3a4c18a3fa(f845355e-b9ad-4884-a217-dd3a4c18a3fa.datForrest Temple"d $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 $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 $0dcbaf26-d634-4ca8-9691-7a8ff966f702(0dcbaf26-d634-4ca8-9691-7a8ff966f702.pngGaro (2\
$cb4c89a7-a421-49ea-8c58-571e9b215d37(cb4c89a7-a421-49ea-8c58-571e9b215d37.pngDeku (2\ $61393836-8127-4277-853f-87b48022ae43(61393836-8127-4277-853f-87b48022ae43.pngCorpse (2^
$9da2c95b-45b7-49e5-957b-c1c8803cdf28(9da2c95b-45b7-49e5-957b-c1c8803cdf28.pngCorpse (2Z $e605b2b1-3cab-499f-882d-160ab65b49d8(e605b2b1-3cab-499f-882d-160ab65b49d8.pngSkeleton (2Z
$4fff029b-6c24-4c83-9dfb-51f5512a687e(4fff029b-6c24-4c83-9dfb-51f5512a687e.pngGaro (2\ $0ea0fe55-53b2-4eea-8fab-2011e694127b(0ea0fe55-53b2-4eea-8fab-2011e694127b.pngLuna (2\
$71414ffb-0e1c-4778-9a1a-0f9f53388fd0(71414ffb-0e1c-4778-9a1a-0f9f53388fd0.pngBlanca (2\ $92ac46ff-8cf2-4748-907f-873030c8e378(92ac46ff-8cf2-4748-907f-873030c8e378.pngChests (2\
$a5c6c6eb-e6cf-4b9e-8c35-11e4c8587ce7(a5c6c6eb-e6cf-4b9e-8c35-11e4c8587ce7.pngTurtle (2\ $fbea4628-e1d3-4acc-800a-ed54c1bb51b6(fbea4628-e1d3-4acc-800a-ed54c1bb51b6.pngBlanca (2[
$15415d5a-2f53-4ee0-8f8f-8e81d702ccdb(15415d5a-2f53-4ee0-8f8f-8e81d702ccdb.pngChests (2[ $7a723b64-e54a-4fff-852d-108349133111(7a723b64-e54a-4fff-852d-108349133111.pngEagle (2\
$a1d5baf4-d5e8-4be9-ba7b-b37ca81b59fb(a1d5baf4-d5e8-4be9-ba7b-b37ca81b59fb.pngEagle (2` $c7ec2341-e5fc-4285-9ecb-a2dfc8a0ed67(c7ec2341-e5fc-4285-9ecb-a2dfc8a0ed67.pngTurtle (2`
$a973f4ec-a7ad-4fd7-8002-b50a854fb733(a973f4ec-a7ad-4fd7-8002-b50a854fb733.png $f1113db3-4a6c-4a07-9b64-32ba8e653e4f(f1113db3-4a6c-4a07-9b64-32ba8e653e4f.png
Silver Bat (2^ Silver Bat (2Z
$55a8c74b-e636-4c0a-9787-1878e672e368(55a8c74b-e636-4c0a-9787-1878e672e368.pngSkeleton (:` $1779ae2b-474a-4599-8fc3-be34f7d66965(1779ae2b-474a-4599-8fc3-be34f7d66965.pngDeku (:`
$2261c04f-b02e-4486-b388-8a0fa41622e9(2261c04f-b02e-4486-b388-8a0fa41622e9.ttfRoboto RegularB\ $2261c04f-b02e-4486-b388-8a0fa41622e9(2261c04f-b02e-4486-b388-8a0fa41622e9.ttfRoboto RegularB\
$ab9d40b4-eb28-45d7-bff2-9432a05eb41a(ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml $ab9d40b4-eb28-45d7-bff2-9432a05eb41a(ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml
Start MenuB[ Start MenuB[

View File

@@ -7,21 +7,21 @@ import com.bartlomiejpluta.base.api.move.Direction;
import com.bartlomiejpluta.base.lib.ai.*; import com.bartlomiejpluta.base.lib.ai.*;
import com.bartlomiejpluta.demo.entity.Enemy; import com.bartlomiejpluta.demo.entity.Enemy;
import com.bartlomiejpluta.demo.entity.Character; import com.bartlomiejpluta.demo.entity.Creature;
public class AnimalAI implements AI { public class AnimalAI implements AI {
private final Enemy animal; private final Enemy animal;
private final Character character; private final Creature creature;
private final int range; private final int range;
private final AI idleAI; private final AI idleAI;
private final AI runawayAI; private final AI runawayAI;
public AnimalAI(Enemy animal, Character character, int range) { public AnimalAI(Enemy animal, Creature creature, int range) {
this.animal = animal; this.animal = animal;
this.character = character; this.creature = creature;
this.range = range; this.range = range;
this.idleAI = new RandomMovementAI<>(animal, 4); this.idleAI = new RandomMovementAI<>(animal, 4);
this.runawayAI = new RunawayAI<>(animal, character); this.runawayAI = new RunawayAI<>(animal, creature);
} }
@Override @Override
@@ -30,7 +30,7 @@ public class AnimalAI implements AI {
return; return;
} }
var distance = animal.manhattanDistance(character); var distance = animal.manhattanDistance(creature);
if(animal.getHp() < animal.getMaxHp() && distance < range) { if(animal.getHp() < animal.getMaxHp() && distance < range) {
runawayAI.nextActivity(layer, dt); runawayAI.nextActivity(layer, dt);

View File

@@ -17,37 +17,37 @@ import org.joml.Vector2i;
import org.joml.Vector2ic; import org.joml.Vector2ic;
import com.bartlomiejpluta.demo.entity.Enemy; import com.bartlomiejpluta.demo.entity.Enemy;
import com.bartlomiejpluta.demo.entity.Character; import com.bartlomiejpluta.demo.entity.Creature;
public class ArcherAI extends KeepStraightDistanceAI<Enemy, Character> { public class ArcherAI extends KeepStraightDistanceAI<Enemy, Creature> {
private static final int ASTAR_MAX_NODES = 100; private static final int ASTAR_MAX_NODES = 100;
private static final int IDLE_MOVEMENT_INTERVAL = 4; private static final int IDLE_MOVEMENT_INTERVAL = 4;
private final int range; private final int range;
private final AI idle; private final AI idle;
public ArcherAI(Enemy enemy, Character target, int minRange, int maxRange, int range) { public ArcherAI(Enemy enemy, Creature target, int minRange, int maxRange, int range) {
super(new AstarPathFinder(ASTAR_MAX_NODES), enemy, target, minRange, maxRange); super(new AstarPathFinder(ASTAR_MAX_NODES), enemy, target, minRange, maxRange);
this.range = range; this.range = range;
this.idle = new RandomMovementAI<>(enemy, IDLE_MOVEMENT_INTERVAL); this.idle = new RandomMovementAI<>(enemy, IDLE_MOVEMENT_INTERVAL);
} }
@Override @Override
protected boolean sees(Enemy enemy, Character target, ObjectLayer layer) { protected boolean sees(Enemy enemy, Creature target, ObjectLayer layer) {
return enemy.manhattanDistance(target) < range; return enemy.manhattanDistance(target) < range;
} }
@Override @Override
protected void interact(Enemy enemy, Character target, ObjectLayer layer, float dt) { protected void interact(Enemy enemy, Creature target, ObjectLayer layer, float dt) {
enemy.attack(); enemy.attack();
} }
@Override @Override
protected void follow(Enemy enemy, Character target, ObjectLayer layer, float dt) { protected void follow(Enemy enemy, Creature target, ObjectLayer layer, float dt) {
// noop // noop
} }
@Override @Override
protected void idle(Enemy enemy, Character target, ObjectLayer layer, float dt) { protected void idle(Enemy enemy, Creature target, ObjectLayer layer, float dt) {
idle.nextActivity(layer, dt); idle.nextActivity(layer, dt);
} }
} }

View File

@@ -7,37 +7,37 @@ import com.bartlomiejpluta.base.api.ai.*;
import com.bartlomiejpluta.base.lib.ai.*; import com.bartlomiejpluta.base.lib.ai.*;
import com.bartlomiejpluta.demo.entity.Enemy; import com.bartlomiejpluta.demo.entity.Enemy;
import com.bartlomiejpluta.demo.entity.Character; import com.bartlomiejpluta.demo.entity.Creature;
public class SimpleEnemyAI extends FollowEntityAI<Enemy, Character> { public class SimpleEnemyAI extends FollowObjectAI<Enemy, Creature> {
private static final int ASTAR_MAX_NODES = 100; private static final int ASTAR_MAX_NODES = 100;
private static final int IDLE_MOVEMENT_INTERVAL = 4; private static final int IDLE_MOVEMENT_INTERVAL = 4;
private final AI idle; private final AI idle;
private final int range; private final int range;
public SimpleEnemyAI(Enemy enemy, Character target, int range) { public SimpleEnemyAI(Enemy enemy, Creature target, int range) {
super(new AstarPathFinder(ASTAR_MAX_NODES), enemy, target); super(new AstarPathFinder(ASTAR_MAX_NODES), enemy, target);
this.range = range; this.range = range;
this.idle = new RandomMovementAI<>(enemy, IDLE_MOVEMENT_INTERVAL); this.idle = new RandomMovementAI<>(enemy, IDLE_MOVEMENT_INTERVAL);
} }
@Override @Override
protected boolean sees(Enemy enemy, Character target, ObjectLayer layer, int distance) { protected boolean sees(Enemy enemy, Creature target, ObjectLayer layer, int distance) {
return distance < range; return distance < range;
} }
@Override @Override
protected void interact(Enemy enemy, Character target, ObjectLayer layer, float dt) { protected void interact(Enemy enemy, Creature target, ObjectLayer layer, float dt) {
enemy.attack(); enemy.attack();
} }
@Override @Override
protected void follow(Enemy enemy, Character target, ObjectLayer layer, float dt) { protected void follow(Enemy enemy, Creature target, ObjectLayer layer, float dt) {
// noop // noop
} }
@Override @Override
protected void idle(Enemy enemy, Character target, ObjectLayer layer, float dt) { protected void idle(Enemy enemy, Creature target, ObjectLayer layer, float dt) {
idle.nextActivity(layer, dt); idle.nextActivity(layer, dt);
} }
} }

View File

@@ -6,12 +6,12 @@ import com.bartlomiejpluta.base.api.ai.*;
import com.bartlomiejpluta.base.lib.ai.*; import com.bartlomiejpluta.base.lib.ai.*;
import com.bartlomiejpluta.demo.entity.Enemy; import com.bartlomiejpluta.demo.entity.Enemy;
import com.bartlomiejpluta.demo.entity.Character; import com.bartlomiejpluta.demo.entity.Creature;
@AllArgsConstructor @AllArgsConstructor
public class SimpleSniperAI implements AI { public class SimpleSniperAI implements AI {
private final Enemy enemy; private final Enemy enemy;
private Character target; private Creature target;
private int range; private int range;
@Override @Override

View File

@@ -6,7 +6,7 @@ import com.bartlomiejpluta.base.api.move.MoveEvent;
import com.bartlomiejpluta.base.api.map.layer.object.ObjectLayer; import com.bartlomiejpluta.base.api.map.layer.object.ObjectLayer;
import com.bartlomiejpluta.base.lib.ai.*; import com.bartlomiejpluta.base.lib.ai.*;
import com.bartlomiejpluta.demo.entity.Character; import com.bartlomiejpluta.demo.entity.Creature;
import com.bartlomiejpluta.demo.entity.Enemy; import com.bartlomiejpluta.demo.entity.Enemy;
import com.bartlomiejpluta.demo.world.weapon.*; import com.bartlomiejpluta.demo.world.weapon.*;
@@ -15,12 +15,12 @@ public class WeaponBasedAI implements AI {
private static final int MIN_RANGE = 3; private static final int MIN_RANGE = 3;
private static final int MAX_RANGE = 12; private static final int MAX_RANGE = 12;
private final Enemy enemy; private final Enemy enemy;
private final Character target; private final Creature target;
private final RunawayAI runawayAI; private final RunawayAI<Enemy, Creature> runawayAI;
private final SimpleEnemyAI meleeAI; private final SimpleEnemyAI meleeAI;
private final ArcherAI archerAI; private final ArcherAI archerAI;
public WeaponBasedAI(@NonNull Enemy enemy, @NonNull Character target) { public WeaponBasedAI(@NonNull Enemy enemy, @NonNull Creature target) {
this.enemy = enemy; this.enemy = enemy;
this.target = target; this.target = target;
this.runawayAI = new RunawayAI<>(enemy, target); this.runawayAI = new RunawayAI<>(enemy, target);
@@ -41,8 +41,8 @@ public class WeaponBasedAI implements AI {
@Override @Override
public void nextActivity(ObjectLayer layer, float dt) { public void nextActivity(ObjectLayer layer, float dt) {
var lastAttacker = enemy.getLastAttacker(); var lastAttacker = enemy.getLastAttacker();
if(lastAttacker != null && lastAttacker instanceof Character) { if(lastAttacker != null && lastAttacker instanceof Creature) {
var attacker = (Character) lastAttacker; var attacker = (Creature) lastAttacker;
if(attacker.isAlive()) { if(attacker.isAlive()) {
runawayAI.setDanger(attacker); runawayAI.setDanger(attacker);
meleeAI.setTarget(attacker); meleeAI.setTarget(attacker);

View File

@@ -4,13 +4,15 @@ import lombok.*;
import org.slf4j.*; import org.slf4j.*;
import org.joml.Vector2i; import org.joml.Vector2i;
import com.bartlomiejpluta.base.api.context.*; import com.bartlomiejpluta.base.api.context.*;
import com.bartlomiejpluta.base.api.character.Character;
import com.bartlomiejpluta.base.api.entity.Entity; import com.bartlomiejpluta.base.api.entity.Entity;
import com.bartlomiejpluta.base.lib.animation.AnimationRunner; import com.bartlomiejpluta.base.lib.animation.AnimationRunner;
import com.bartlomiejpluta.demo.world.weapon.Weapon; import com.bartlomiejpluta.demo.world.weapon.Weapon;
public abstract class Character extends NamedEntity { public abstract class Creature extends NamedCharacter {
private static final Logger log = LoggerFactory.getLogger(Character.class); private static final Logger log = LoggerFactory.getLogger(Creature.class);
protected int attackCooldown = 0; protected int attackCooldown = 0;
@@ -31,9 +33,9 @@ public abstract class Character extends NamedEntity {
private Weapon weapon; private Weapon weapon;
@Getter @Getter
private NamedEntity lastAttacker; private NamedCharacter lastAttacker;
public Character(@NonNull Entity entity) { public Creature(@NonNull Character entity) {
super(entity); super(entity);
} }
@@ -49,7 +51,7 @@ public abstract class Character extends NamedEntity {
} }
} }
public void hit(NamedEntity source, int dmg) { public void hit(NamedCharacter source, int dmg) {
this.lastAttacker = source; this.lastAttacker = source;
if(immortal) { if(immortal) {

View File

@@ -4,6 +4,7 @@ import lombok.*;
import com.bartlomiejpluta.base.api.context.*; import com.bartlomiejpluta.base.api.context.*;
import com.bartlomiejpluta.base.api.entity.Entity; import com.bartlomiejpluta.base.api.entity.Entity;
import com.bartlomiejpluta.base.api.character.Character;
import com.bartlomiejpluta.base.api.ai.AI; import com.bartlomiejpluta.base.api.ai.AI;
import com.bartlomiejpluta.base.api.ai.NPC; import com.bartlomiejpluta.base.api.ai.NPC;
import com.bartlomiejpluta.base.api.move.MoveEvent; import com.bartlomiejpluta.base.api.move.MoveEvent;
@@ -19,7 +20,7 @@ import com.bartlomiejpluta.demo.ai.*;
import com.bartlomiejpluta.demo.ai.ArcherAI; import com.bartlomiejpluta.demo.ai.ArcherAI;
public class Enemy extends Character implements NPC { public class Enemy extends Creature implements NPC {
private final DB.model.EnemyModel template; private final DB.model.EnemyModel template;
private AI ai = NoopAI.INSTANCE; private AI ai = NoopAI.INSTANCE;
private final AnimationRunner dieAnimation; private final AnimationRunner dieAnimation;
@@ -38,7 +39,7 @@ public class Enemy extends Character implements NPC {
} }
public Enemy(@NonNull DB.model.EnemyModel template) { public Enemy(@NonNull DB.model.EnemyModel template) {
super(ContextHolder.INSTANCE.getContext().createEntity(template.getEntset())); super(ContextHolder.INSTANCE.getContext().createCharacter(A.charsets.get(template.getCharset()).uid));
this.template = template; this.template = template;
name = template.getName(); name = template.getName();
maxHp = DiceRoller.of(template.getHp()).roll(); maxHp = DiceRoller.of(template.getHp()).roll();
@@ -58,7 +59,7 @@ public class Enemy extends Character implements NPC {
this.rangedWeapon = new RangedWeapon(rangedWeaponTemplate); this.rangedWeapon = new RangedWeapon(rangedWeaponTemplate);
} }
this.dieAnimation = new SimpleAnimationRunner(template.getDieAnimation()); this.dieAnimation = new SimpleAnimationRunner(A.animations.get(template.getDieAnimation()).uid);
} }
@Override @Override
@@ -69,7 +70,7 @@ public class Enemy extends Character implements NPC {
@Override @Override
public void die() { public void die() {
super.die(); super.die();
changeEntitySet(template.getDeadEntset()); changeCharacterSet(A.charsets.get(template.getDeadCharset()).uid);
setScale(0.5f); setScale(0.5f);
setBlocking(false); setBlocking(false);
setZIndex(-1); setZIndex(-1);
@@ -77,11 +78,11 @@ public class Enemy extends Character implements NPC {
ai = NoopAI.INSTANCE; ai = NoopAI.INSTANCE;
dieAnimation.run(context, getLayer(), this); dieAnimation.run(context, getLayer(), this);
context.playSound(template.getDieSound()); context.playSound(A.sounds.get(template.getDieSound()).uid);
context.fireEvent(new EnemyDiedEvent(this)); context.fireEvent(new EnemyDiedEvent(this));
} }
public Enemy followAndAttack(Character target, int range) { public Enemy followAndAttack(Creature target, int range) {
var ai = new SimpleEnemyAI(this, target, range); var ai = new SimpleEnemyAI(this, target, range);
addEventListener(MoveEvent.TYPE, ai::recomputePath); addEventListener(MoveEvent.TYPE, ai::recomputePath);
@@ -92,19 +93,19 @@ public class Enemy extends Character implements NPC {
return this; return this;
} }
public Enemy campAndHunt(Character target, int range) { public Enemy campAndHunt(Creature target, int range) {
this.ai = new SimpleSniperAI(this, target, range); this.ai = new SimpleSniperAI(this, target, range);
return this; return this;
} }
public Enemy asAnimal(Character source, int range) { public Enemy asAnimal(Creature source, int range) {
this.ai = new AnimalAI(this, source, range); this.ai = new AnimalAI(this, source, range);
return this; return this;
} }
public Enemy archer(Character target, int minRange, int maxRange, int range) { public Enemy archer(Creature target, int minRange, int maxRange, int range) {
var ai = new ArcherAI(this, target, minRange, maxRange, range); var ai = new ArcherAI(this, target, minRange, maxRange, range);
addEventListener(MoveEvent.TYPE, ai::recomputePath); addEventListener(MoveEvent.TYPE, ai::recomputePath);

View File

@@ -4,12 +4,9 @@ import lombok.*;
import com.bartlomiejpluta.base.api.entity.Entity; import com.bartlomiejpluta.base.api.entity.Entity;
import com.bartlomiejpluta.base.api.context.*; import com.bartlomiejpluta.base.api.context.*;
import com.bartlomiejpluta.base.api.move.*; import com.bartlomiejpluta.base.api.move.*;
import com.bartlomiejpluta.base.lib.entity.EntityDelegate;
import com.bartlomiejpluta.base.util.path.*; import com.bartlomiejpluta.base.util.path.*;
import com.bartlomiejpluta.demo.entity.Character; public class MapObject extends NamedCharacter {
public class MapObject extends NamedEntity {
private final PathExecutor<MapObject> pathExecutor = new PathExecutor<>(this); private final PathExecutor<MapObject> pathExecutor = new PathExecutor<>(this);
private final DB.model.MapObjectModel template; private final DB.model.MapObjectModel template;
private final Short frame; private final Short frame;
@@ -25,11 +22,11 @@ public class MapObject extends NamedEntity {
} }
public MapObject(@NonNull DB.model.MapObjectModel template) { public MapObject(@NonNull DB.model.MapObjectModel template) {
super(ContextHolder.INSTANCE.getContext().createEntity(template.getEntset())); super(ContextHolder.INSTANCE.getContext().createCharacter(A.charsets.get(template.getCharset()).uid));
this.template = template; this.template = template;
this.frame = template.getFrame(); this.frame = template.getFrame();
this.name = template.getName(); this.name = template.getName();
this.interactSound = template.getInteractSound(); this.interactSound = A.sounds.get(template.getInteractSound()).uid;
setBlocking(true); setBlocking(true);
disableAnimation(); disableAnimation();
@@ -40,7 +37,7 @@ public class MapObject extends NamedEntity {
pathExecutor.setPath( pathExecutor.setPath(
frame != null frame != null
? new EntityPath<MapObject>() ? new CharacterPath<MapObject>()
.run(this::startInteraction) .run(this::startInteraction)
.turn(Direction.LEFT, frame) .turn(Direction.LEFT, frame)
.wait(0.05f) .wait(0.05f)
@@ -55,11 +52,11 @@ public class MapObject extends NamedEntity {
.turn(Direction.DOWN, frame) .turn(Direction.DOWN, frame)
.wait(0.5f) .wait(0.5f)
.run(this::finishInteraction) .run(this::finishInteraction)
: new EntityPath<MapObject>() : new CharacterPath<MapObject>()
); );
} }
public void interact(Character character) { public void interact(Creature creature) {
interacting = true; interacting = true;
} }

View File

@@ -2,16 +2,17 @@ package com.bartlomiejpluta.demo.entity;
import com.bartlomiejpluta.base.api.context.*; import com.bartlomiejpluta.base.api.context.*;
import com.bartlomiejpluta.base.api.entity.Entity; import com.bartlomiejpluta.base.api.entity.Entity;
import com.bartlomiejpluta.base.lib.entity.EntityDelegate; import com.bartlomiejpluta.base.lib.character.CharacterDelegate;
import com.bartlomiejpluta.base.api.character.Character;
import com.bartlomiejpluta.demo.runner.DemoRunner; import com.bartlomiejpluta.demo.runner.DemoRunner;
public abstract class NamedEntity extends EntityDelegate { public abstract class NamedCharacter extends CharacterDelegate {
protected final Context context; protected final Context context;
protected final DemoRunner runner; protected final DemoRunner runner;
public NamedEntity(Entity entity) { public NamedCharacter(Character character) {
super(entity); super(character);
this.context = ContextHolder.INSTANCE.getContext(); this.context = ContextHolder.INSTANCE.getContext();
this.runner = (DemoRunner) context.getGameRunner(); this.runner = (DemoRunner) context.getGameRunner();
} }

View File

@@ -4,11 +4,11 @@ import lombok.*;
import org.joml.Vector2i; import org.joml.Vector2i;
import com.bartlomiejpluta.base.api.context.Context; import com.bartlomiejpluta.base.api.context.Context;
import com.bartlomiejpluta.base.api.entity.Entity; import com.bartlomiejpluta.base.api.entity.Entity;
import com.bartlomiejpluta.demo.entity.MapObject; import com.bartlomiejpluta.base.api.character.Character;
public class Player extends Character { public class Player extends Creature {
public Player(@NonNull Entity entity) { public Player(@NonNull Character entity) {
super(entity); super(entity);
this.hp = 500; this.hp = 500;
this.maxHp = 500; this.maxHp = 500;

View File

@@ -4,15 +4,15 @@ import lombok.*;
import com.bartlomiejpluta.base.api.event.*; import com.bartlomiejpluta.base.api.event.*;
import com.bartlomiejpluta.base.lib.event.*; import com.bartlomiejpluta.base.lib.event.*;
import com.bartlomiejpluta.demo.entity.Character; import com.bartlomiejpluta.demo.entity.Creature;
@Getter @Getter
@RequiredArgsConstructor @RequiredArgsConstructor
public class HitEvent extends BaseEvent { public class HitEvent extends BaseEvent {
public static final EventType<HitEvent> TYPE = new EventType<>("HIT_EVENT"); public static final EventType<HitEvent> TYPE = new EventType<>("HIT_EVENT");
private final Character attacker; private final Creature attacker;
private final Character target; private final Creature target;
private final int damage; private final int damage;
@Override @Override

View File

@@ -13,7 +13,7 @@ import com.bartlomiejpluta.base.api.input.*;
import com.bartlomiejpluta.base.lib.camera.*; import com.bartlomiejpluta.base.lib.camera.*;
import com.bartlomiejpluta.base.util.world.EntitySpawner; import com.bartlomiejpluta.base.util.world.CharacterSpawner;
import com.bartlomiejpluta.demo.runner.DemoRunner; import com.bartlomiejpluta.demo.runner.DemoRunner;
import com.bartlomiejpluta.demo.entity.*; import com.bartlomiejpluta.demo.entity.*;
@@ -33,7 +33,7 @@ public abstract class BaseMapHandler implements MapHandler {
protected Player player; protected Player player;
protected ObjectLayer mainLayer; protected ObjectLayer mainLayer;
protected CameraController cameraController; protected CameraController cameraController;
protected final List<EntitySpawner> spawners = new LinkedList<>(); protected final List<CharacterSpawner> spawners = new LinkedList<>();
@Override @Override
public void onCreate(Context context, GameMap map) { public void onCreate(Context context, GameMap map) {
@@ -111,8 +111,8 @@ public abstract class BaseMapHandler implements MapHandler {
return object; return object;
} }
public EntitySpawner spawner(int x, int y, ObjectLayer layer) { public CharacterSpawner spawner(int x, int y, ObjectLayer layer) {
var spawner = new EntitySpawner(x, y, context, map, layer).trackEntities(EnemyDiedEvent.TYPE); var spawner = new CharacterSpawner(x, y, context, map, layer).trackEntities(EnemyDiedEvent.TYPE);
this.spawners.add(spawner); this.spawners.add(spawner);
return spawner; return spawner;
} }

View File

@@ -70,11 +70,11 @@ public class DemoRunner implements GameRunner {
} }
private void initPlayer() { private void initPlayer() {
this.player = new Player(context.createEntity(A.entsets.luna.uid)); this.player = new Player(context.createCharacter(A.charsets.luna.uid));
} }
private void resetPlayer() { private void resetPlayer() {
this.player.changeEntitySet(A.entsets.luna.uid); this.player.changeCharacterSet(A.charsets.luna.uid);
this.player.setScale(1.0f); this.player.setScale(1.0f);
this.player.setSpeed(0.07f); this.player.setSpeed(0.07f);
this.player.setAnimationSpeed(0.005f); this.player.setAnimationSpeed(0.005f);

View File

@@ -8,7 +8,7 @@ import com.bartlomiejpluta.base.api.context.*;
import com.bartlomiejpluta.base.lib.animation.*; import com.bartlomiejpluta.base.lib.animation.*;
import com.bartlomiejpluta.base.util.random.DiceRoller; import com.bartlomiejpluta.base.util.random.DiceRoller;
import com.bartlomiejpluta.demo.entity.Character; import com.bartlomiejpluta.demo.entity.Creature;
import com.bartlomiejpluta.demo.event.HitEvent; import com.bartlomiejpluta.demo.event.HitEvent;
@@ -40,16 +40,16 @@ public class MeleeWeapon implements Weapon {
.uAnimationSpeed(0.01f, 0.05f) .uAnimationSpeed(0.01f, 0.05f)
.offset(0, -10) .offset(0, -10)
.uDelay(0, 500) .uDelay(0, 500)
.with(template.getAnimation()); .with(A.animations.get(template.getAnimation()).uid);
this.sound = template.getSound(); this.sound = A.sounds.get(template.getSound()).uid;
} }
@Override @Override
public boolean attack(Character attacker) { public boolean attack(Creature attacker) {
var facingNeighbour = attacker.getCoordinates().add(attacker.getFaceDirection().vector, new Vector2i()); var facingNeighbour = attacker.getCoordinates().add(attacker.getFaceDirection().vector, new Vector2i());
for(var entity : attacker.getLayer().getEntities()) { for(var entity : attacker.getLayer().getEntities()) {
if(entity.getCoordinates().equals(facingNeighbour) && entity.isBlocking() && entity instanceof Character) { if(entity.getCoordinates().equals(facingNeighbour) && entity.isBlocking() && entity instanceof Creature) {
var character = (Character) entity; var character = (Creature) entity;
var damage = roller.roll(); var damage = roller.roll();
character.hit(attacker, damage); character.hit(attacker, damage);
animation.run(context, character.getLayer(), character); animation.run(context, character.getLayer(), character);

View File

@@ -10,8 +10,7 @@ import com.bartlomiejpluta.base.api.move.*;
import com.bartlomiejpluta.base.lib.animation.*; import com.bartlomiejpluta.base.lib.animation.*;
import com.bartlomiejpluta.base.util.random.DiceRoller; import com.bartlomiejpluta.base.util.random.DiceRoller;
import com.bartlomiejpluta.demo.entity.Character; import com.bartlomiejpluta.demo.entity.Creature;
import com.bartlomiejpluta.demo.entity.NamedEntity;
import com.bartlomiejpluta.demo.event.HitEvent; import com.bartlomiejpluta.demo.event.HitEvent;
@@ -43,7 +42,7 @@ public class RangedWeapon implements Weapon {
this.dmgRoller = DiceRoller.of(template.getDamage()); this.dmgRoller = DiceRoller.of(template.getDamage());
this.rangeRoller = DiceRoller.of(template.getRange()); this.rangeRoller = DiceRoller.of(template.getRange());
this.cooldown = template.getCooldown(); this.cooldown = template.getCooldown();
this.animation = new BulletAnimationRunner(template.getAnimation()) this.animation = new BulletAnimationRunner(A.animations.get(template.getAnimation()).uid)
.infinite() .infinite()
.offset(0, -15) .offset(0, -15)
.onHit(this::onHit) .onHit(this::onHit)
@@ -51,18 +50,18 @@ public class RangedWeapon implements Weapon {
.speed(0.25f) .speed(0.25f)
.animationSpeed(0.07f) .animationSpeed(0.07f)
.scale(0.6f); .scale(0.6f);
this.sound = template.getSound(); this.sound = A.sounds.get(template.getSound()).uid;
this.punchAnimation = new SimpleAnimationRunner(template.getPunchAnimation()); this.punchAnimation = new SimpleAnimationRunner(A.animations.get(template.getPunchAnimation()).uid);
this.punchSound = template.getPunchSound(); this.punchSound = A.sounds.get(template.getPunchSound()).uid;
this.missAnimation = new SimpleAnimationRunner(template.getMissAnimation()) this.missAnimation = new SimpleAnimationRunner(A.animations.get(template.getMissAnimation()).uid)
.scale(0.4f); .scale(0.4f);
this.missSound = template.getMissSound(); this.missSound = A.sounds.get(template.getMissSound()).uid;
} }
private void onHit(Movable attacker, Entity target) { private void onHit(Movable attacker, Entity target) {
if(target.isBlocking() && target instanceof Character) { if(target.isBlocking() && target instanceof Creature) {
var namedAttacker = (Character) attacker; var namedAttacker = (Creature) attacker;
var character = (Character) target; var character = (Creature) target;
var damage = dmgRoller.roll(); var damage = dmgRoller.roll();
character.hit(namedAttacker, damage); character.hit(namedAttacker, damage);
punchAnimation.run(context, character.getLayer(), character); punchAnimation.run(context, character.getLayer(), character);
@@ -72,12 +71,12 @@ public class RangedWeapon implements Weapon {
} }
private void onMiss(Movable attacker, Animation animation) { private void onMiss(Movable attacker, Animation animation) {
missAnimation.run(context, ((Character) attacker).getLayer(), animation.getPosition()); missAnimation.run(context, ((Creature) attacker).getLayer(), animation.getPosition());
context.playSound(missSound); context.playSound(missSound);
} }
@Override @Override
public boolean attack(Character attacker) { public boolean attack(Creature attacker) {
var direction = attacker.getFaceDirection(); var direction = attacker.getFaceDirection();
context.playSound(sound); context.playSound(sound);
animation animation

View File

@@ -1,9 +1,9 @@
package com.bartlomiejpluta.demo.world.weapon; package com.bartlomiejpluta.demo.world.weapon;
import com.bartlomiejpluta.demo.entity.Character; import com.bartlomiejpluta.demo.entity.Creature;
public interface Weapon { public interface Weapon {
String getName(); String getName();
int getCooldown(); int getCooldown();
boolean attack(Character attacker); boolean attack(Creature attacker);
} }