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`
$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 (2\
$9da2c95b-45b7-49e5-957b-c1c8803cdf28(9da2c95b-45b7-49e5-957b-c1c8803cdf28.pngCorpse (2Z
$4fff029b-6c24-4c83-9dfb-51f5512a687e(4fff029b-6c24-4c83-9dfb-51f5512a687e.pngGaro (2\
$71414ffb-0e1c-4778-9a1a-0f9f53388fd0(71414ffb-0e1c-4778-9a1a-0f9f53388fd0.pngBlanca (2\
$a5c6c6eb-e6cf-4b9e-8c35-11e4c8587ce7(a5c6c6eb-e6cf-4b9e-8c35-11e4c8587ce7.pngTurtle (2\
$15415d5a-2f53-4ee0-8f8f-8e81d702ccdb(15415d5a-2f53-4ee0-8f8f-8e81d702ccdb.pngChests (2[
$a1d5baf4-d5e8-4be9-ba7b-b37ca81b59fb(a1d5baf4-d5e8-4be9-ba7b-b37ca81b59fb.pngEagle (2`
$a973f4ec-a7ad-4fd7-8002-b50a854fb733(a973f4ec-a7ad-4fd7-8002-b50a854fb733.png
Silver Bat (2^
$55a8c74b-e636-4c0a-9787-1878e672e368(55a8c74b-e636-4c0a-9787-1878e672e368.pngSkeleton (:`
$0dcbaf26-d634-4ca8-9691-7a8ff966f702(0dcbaf26-d634-4ca8-9691-7a8ff966f702.pngGaro (2\
$61393836-8127-4277-853f-87b48022ae43(61393836-8127-4277-853f-87b48022ae43.pngCorpse (2^
$e605b2b1-3cab-499f-882d-160ab65b49d8(e605b2b1-3cab-499f-882d-160ab65b49d8.pngSkeleton (2Z
$0ea0fe55-53b2-4eea-8fab-2011e694127b(0ea0fe55-53b2-4eea-8fab-2011e694127b.pngLuna (2\
$92ac46ff-8cf2-4748-907f-873030c8e378(92ac46ff-8cf2-4748-907f-873030c8e378.pngChests (2\
$fbea4628-e1d3-4acc-800a-ed54c1bb51b6(fbea4628-e1d3-4acc-800a-ed54c1bb51b6.pngBlanca (2[
$7a723b64-e54a-4fff-852d-108349133111(7a723b64-e54a-4fff-852d-108349133111.pngEagle (2\
$c7ec2341-e5fc-4285-9ecb-a2dfc8a0ed67(c7ec2341-e5fc-4285-9ecb-a2dfc8a0ed67.pngTurtle (2`
$f1113db3-4a6c-4a07-9b64-32ba8e653e4f(f1113db3-4a6c-4a07-9b64-32ba8e653e4f.png
Silver Bat (2Z
$1779ae2b-474a-4599-8fc3-be34f7d66965(1779ae2b-474a-4599-8fc3-be34f7d66965.pngDeku (:`
$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[

View File

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

View File

@@ -17,37 +17,37 @@ import org.joml.Vector2i;
import org.joml.Vector2ic;
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 IDLE_MOVEMENT_INTERVAL = 4;
private final int range;
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);
this.range = range;
this.idle = new RandomMovementAI<>(enemy, IDLE_MOVEMENT_INTERVAL);
}
@Override
protected boolean sees(Enemy enemy, Character target, ObjectLayer layer) {
protected boolean sees(Enemy enemy, Creature target, ObjectLayer layer) {
return enemy.manhattanDistance(target) < range;
}
@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();
}
@Override
protected void follow(Enemy enemy, Character target, ObjectLayer layer, float dt) {
protected void follow(Enemy enemy, Creature target, ObjectLayer layer, float dt) {
// noop
}
@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);
}
}

View File

@@ -7,37 +7,37 @@ import com.bartlomiejpluta.base.api.ai.*;
import com.bartlomiejpluta.base.lib.ai.*;
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 IDLE_MOVEMENT_INTERVAL = 4;
private final AI idle;
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);
this.range = range;
this.idle = new RandomMovementAI<>(enemy, IDLE_MOVEMENT_INTERVAL);
}
@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;
}
@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();
}
@Override
protected void follow(Enemy enemy, Character target, ObjectLayer layer, float dt) {
protected void follow(Enemy enemy, Creature target, ObjectLayer layer, float dt) {
// noop
}
@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);
}
}

View File

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

View File

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

View File

@@ -4,6 +4,7 @@ import lombok.*;
import com.bartlomiejpluta.base.api.context.*;
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.NPC;
import com.bartlomiejpluta.base.api.move.MoveEvent;
@@ -19,7 +20,7 @@ import com.bartlomiejpluta.demo.ai.*;
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 AI ai = NoopAI.INSTANCE;
private final AnimationRunner dieAnimation;
@@ -38,7 +39,7 @@ public class Enemy extends Character implements NPC {
}
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;
name = template.getName();
maxHp = DiceRoller.of(template.getHp()).roll();
@@ -58,7 +59,7 @@ public class Enemy extends Character implements NPC {
this.rangedWeapon = new RangedWeapon(rangedWeaponTemplate);
}
this.dieAnimation = new SimpleAnimationRunner(template.getDieAnimation());
this.dieAnimation = new SimpleAnimationRunner(A.animations.get(template.getDieAnimation()).uid);
}
@Override
@@ -69,7 +70,7 @@ public class Enemy extends Character implements NPC {
@Override
public void die() {
super.die();
changeEntitySet(template.getDeadEntset());
changeCharacterSet(A.charsets.get(template.getDeadCharset()).uid);
setScale(0.5f);
setBlocking(false);
setZIndex(-1);
@@ -77,11 +78,11 @@ public class Enemy extends Character implements NPC {
ai = NoopAI.INSTANCE;
dieAnimation.run(context, getLayer(), this);
context.playSound(template.getDieSound());
context.playSound(A.sounds.get(template.getDieSound()).uid);
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);
addEventListener(MoveEvent.TYPE, ai::recomputePath);
@@ -92,19 +93,19 @@ public class Enemy extends Character implements NPC {
return this;
}
public Enemy campAndHunt(Character target, int range) {
public Enemy campAndHunt(Creature target, int range) {
this.ai = new SimpleSniperAI(this, target, range);
return this;
}
public Enemy asAnimal(Character source, int range) {
public Enemy asAnimal(Creature source, int range) {
this.ai = new AnimalAI(this, source, range);
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);
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.context.*;
import com.bartlomiejpluta.base.api.move.*;
import com.bartlomiejpluta.base.lib.entity.EntityDelegate;
import com.bartlomiejpluta.base.util.path.*;
import com.bartlomiejpluta.demo.entity.Character;
public class MapObject extends NamedEntity {
public class MapObject extends NamedCharacter {
private final PathExecutor<MapObject> pathExecutor = new PathExecutor<>(this);
private final DB.model.MapObjectModel template;
private final Short frame;
@@ -25,11 +22,11 @@ public class MapObject extends NamedEntity {
}
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.frame = template.getFrame();
this.name = template.getName();
this.interactSound = template.getInteractSound();
this.interactSound = A.sounds.get(template.getInteractSound()).uid;
setBlocking(true);
disableAnimation();
@@ -40,7 +37,7 @@ public class MapObject extends NamedEntity {
pathExecutor.setPath(
frame != null
? new EntityPath<MapObject>()
? new CharacterPath<MapObject>()
.run(this::startInteraction)
.turn(Direction.LEFT, frame)
.wait(0.05f)
@@ -55,11 +52,11 @@ public class MapObject extends NamedEntity {
.turn(Direction.DOWN, frame)
.wait(0.5f)
.run(this::finishInteraction)
: new EntityPath<MapObject>()
: new CharacterPath<MapObject>()
);
}
public void interact(Character character) {
public void interact(Creature creature) {
interacting = true;
}

View File

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

View File

@@ -4,11 +4,11 @@ import lombok.*;
import org.joml.Vector2i;
import com.bartlomiejpluta.base.api.context.Context;
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);
this.hp = 500;
this.maxHp = 500;

View File

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

View File

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

View File

@@ -70,11 +70,11 @@ public class DemoRunner implements GameRunner {
}
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() {
this.player.changeEntitySet(A.entsets.luna.uid);
this.player.changeCharacterSet(A.charsets.luna.uid);
this.player.setScale(1.0f);
this.player.setSpeed(0.07f);
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.util.random.DiceRoller;
import com.bartlomiejpluta.demo.entity.Character;
import com.bartlomiejpluta.demo.entity.Creature;
import com.bartlomiejpluta.demo.event.HitEvent;
@@ -40,16 +40,16 @@ public class MeleeWeapon implements Weapon {
.uAnimationSpeed(0.01f, 0.05f)
.offset(0, -10)
.uDelay(0, 500)
.with(template.getAnimation());
this.sound = template.getSound();
.with(A.animations.get(template.getAnimation()).uid);
this.sound = A.sounds.get(template.getSound()).uid;
}
@Override
public boolean attack(Character attacker) {
public boolean attack(Creature attacker) {
var facingNeighbour = attacker.getCoordinates().add(attacker.getFaceDirection().vector, new Vector2i());
for(var entity : attacker.getLayer().getEntities()) {
if(entity.getCoordinates().equals(facingNeighbour) && entity.isBlocking() && entity instanceof Character) {
var character = (Character) entity;
if(entity.getCoordinates().equals(facingNeighbour) && entity.isBlocking() && entity instanceof Creature) {
var character = (Creature) entity;
var damage = roller.roll();
character.hit(attacker, damage);
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.util.random.DiceRoller;
import com.bartlomiejpluta.demo.entity.Character;
import com.bartlomiejpluta.demo.entity.NamedEntity;
import com.bartlomiejpluta.demo.entity.Creature;
import com.bartlomiejpluta.demo.event.HitEvent;
@@ -43,7 +42,7 @@ public class RangedWeapon implements Weapon {
this.dmgRoller = DiceRoller.of(template.getDamage());
this.rangeRoller = DiceRoller.of(template.getRange());
this.cooldown = template.getCooldown();
this.animation = new BulletAnimationRunner(template.getAnimation())
this.animation = new BulletAnimationRunner(A.animations.get(template.getAnimation()).uid)
.infinite()
.offset(0, -15)
.onHit(this::onHit)
@@ -51,18 +50,18 @@ public class RangedWeapon implements Weapon {
.speed(0.25f)
.animationSpeed(0.07f)
.scale(0.6f);
this.sound = template.getSound();
this.punchAnimation = new SimpleAnimationRunner(template.getPunchAnimation());
this.punchSound = template.getPunchSound();
this.missAnimation = new SimpleAnimationRunner(template.getMissAnimation())
this.sound = A.sounds.get(template.getSound()).uid;
this.punchAnimation = new SimpleAnimationRunner(A.animations.get(template.getPunchAnimation()).uid);
this.punchSound = A.sounds.get(template.getPunchSound()).uid;
this.missAnimation = new SimpleAnimationRunner(A.animations.get(template.getMissAnimation()).uid)
.scale(0.4f);
this.missSound = template.getMissSound();
this.missSound = A.sounds.get(template.getMissSound()).uid;
}
private void onHit(Movable attacker, Entity target) {
if(target.isBlocking() && target instanceof Character) {
var namedAttacker = (Character) attacker;
var character = (Character) target;
if(target.isBlocking() && target instanceof Creature) {
var namedAttacker = (Creature) attacker;
var character = (Creature) target;
var damage = dmgRoller.roll();
character.hit(namedAttacker, damage);
punchAnimation.run(context, character.getLayer(), character);
@@ -72,12 +71,12 @@ public class RangedWeapon implements Weapon {
}
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);
}
@Override
public boolean attack(Character attacker) {
public boolean attack(Creature attacker) {
var direction = attacker.getFaceDirection();
context.playSound(sound);
animation

View File

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