diff --git a/animations/0ddac391-4086-4e9c-8310-59db649419ff.png b/animations/0ddac391-4086-4e9c-8310-59db649419ff.png new file mode 100644 index 0000000..c0fe394 Binary files /dev/null and b/animations/0ddac391-4086-4e9c-8310-59db649419ff.png differ diff --git a/animations/61e67e44-a0cd-4210-8d1e-ccddcd62c78d.png b/animations/61e67e44-a0cd-4210-8d1e-ccddcd62c78d.png deleted file mode 100644 index 192a81c..0000000 Binary files a/animations/61e67e44-a0cd-4210-8d1e-ccddcd62c78d.png and /dev/null differ diff --git a/data.mv.db b/data.mv.db index ba6c01b..1eb551e 100644 Binary files a/data.mv.db and b/data.mv.db differ diff --git a/project.bep b/project.bep index 2631a3b..1f6a970 100644 --- a/project.bep +++ b/project.bep @@ -18,11 +18,11 @@ $2261c04f-b02e-4486-b388-8a0fa41622e9(2261c04f-b02e-4486-b388-8a0fa41622e9.ttf $ab9d40b4-eb28-45d7-bff2-9432a05eb41a(ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml Start MenuB[ $56ca6b39-f949-4212-9c23-312db25887e0(56ca6b39-f949-4212-9c23-312db25887e0.xml Game MenuBU -$00bd0625-b3b8-4abf-97b7-91f42bce28ec(00bd0625-b3b8-4abf-97b7-91f42bce28ec.xmlHUDJ[ -$61e67e44-a0cd-4210-8d1e-ccddcd62c78d(61e67e44-a0cd-4210-8d1e-ccddcd62c78d.pngSlash (JZ +$00bd0625-b3b8-4abf-97b7-91f42bce28ec(00bd0625-b3b8-4abf-97b7-91f42bce28ec.xmlHUDJZ $e6f067f1-eba0-4e62-99c3-2fd867e6f142(e6f067f1-eba0-4e62-99c3-2fd867e6f142.pngPoof (J[ $312cc4e6-8c44-43e7-828a-e7e2a77836f3(312cc4e6-8c44-43e7-828a-e7e2a77836f3.pngArrow (J[ -$54f657bd-8108-464c-9bbe-63944fc14f6b(54f657bd-8108-464c-9bbe-63944fc14f6b.pngPunch (R] +$54f657bd-8108-464c-9bbe-63944fc14f6b(54f657bd-8108-464c-9bbe-63944fc14f6b.pngPunch (J[ +$0ddac391-4086-4e9c-8310-59db649419ff(0ddac391-4086-4e9c-8310-59db649419ff.pngSlash (R] $1311327d-4b74-4252-94da-23ee4129e357(1311327d-4b74-4252-94da-23ee4129e357.ogg Sword slashR\ $e452e215-f581-40fe-a5cf-f555d3db83b8(e452e215-f581-40fe-a5cf-f555d3db83b8.ogg Deku deathRW diff --git a/src/main/java/com/bartlomiejpluta/demo/gui/HUD.java b/src/main/java/com/bartlomiejpluta/demo/gui/HUD.java index 435dbeb..2e53734 100644 --- a/src/main/java/com/bartlomiejpluta/demo/gui/HUD.java +++ b/src/main/java/com/bartlomiejpluta/demo/gui/HUD.java @@ -1,100 +1,98 @@ package com.bartlomiejpluta.demo.gui; -import lombok.extern.slf4j.Slf4j; - -import com.bartlomiejpluta.base.api.gui.*; -import com.bartlomiejpluta.base.lib.gui.*; - -import com.bartlomiejpluta.base.api.screen.*; import com.bartlomiejpluta.base.api.context.Context; +import com.bartlomiejpluta.base.api.gui.*; import com.bartlomiejpluta.base.api.input.*; - +import com.bartlomiejpluta.base.api.screen.*; +import com.bartlomiejpluta.base.lib.gui.*; +import com.bartlomiejpluta.demo.entity.Player; +import com.bartlomiejpluta.demo.event.EnemyDiedEvent; +import com.bartlomiejpluta.demo.event.HitEvent; import com.bartlomiejpluta.demo.runner.DemoRunner; -import com.bartlomiejpluta.demo.entity.*; - -import com.bartlomiejpluta.demo.event.*; import com.bartlomiejpluta.demo.util.LimitedQueue; +import com.bartlomiejpluta.demo.world.weapon.Weapon; +import lombok.extern.slf4j.Slf4j; import java.util.stream.Collectors; @Slf4j public class HUD extends BorderLayout { - private static final int MAX_LOG_SIZE = 10; - private static final float LOG_VISIBILITY_DURATION = 8000f; - private static final float LOG_VISIBILITY_FADING_OUT = 1000f; - private final DemoRunner runner; - private final Player player; - private final Runtime runtime; - private LimitedQueue logger = new LimitedQueue<>(MAX_LOG_SIZE); + private static final int MAX_LOG_SIZE = 10; + private static final float LOG_VISIBILITY_DURATION = 8000f; + private static final float LOG_VISIBILITY_FADING_OUT = 1000f; + private final DemoRunner runner; + private final Player player; + private final Runtime runtime; + private LimitedQueue logger = new LimitedQueue<>(MAX_LOG_SIZE); - private float logVisibilityDuration = 0f; + private float logVisibilityDuration = 0f; - @Ref("hp") - private Bar hp; + private Weapon currentWeapon; - @Ref("debug") - private Label debugLbl; + @Ref("hp") + private Bar hp; - @Ref("log") - private Label logLbl; + @Ref("debug") + private Label debugLbl; - public HUD(Context context, GUI gui) { - super(context, gui); - this.runner = (DemoRunner) context.getGameRunner(); - this.player = runner.getPlayer(); - this.runtime = Runtime.getRuntime(); - context.addEventListener(HitEvent.TYPE, this::logHitEvent); - context.addEventListener(EnemyDiedEvent.TYPE, this::logEnemyDiedEvent); - } + @Ref("log") + private Label logLbl; - private void logHitEvent(HitEvent event) { - log(String.format("%s hits %s with damage = %d", event.getAttacker().getName(), event.getTarget().getName(), event.getDamage())); - } + @Ref("weapon") + private IconView weapon; - private void log(String message) { - logger.add(message); - log.info(message); - logLbl.setText(logger.stream().collect(Collectors.joining("\n"))); - logVisibilityDuration = LOG_VISIBILITY_DURATION; - } + public HUD(Context context, GUI gui) { + super(context, gui); + this.runner = (DemoRunner) context.getGameRunner(); + this.player = runner.getPlayer(); + this.runtime = Runtime.getRuntime(); + context.addEventListener(HitEvent.TYPE, this::logHitEvent); + context.addEventListener(EnemyDiedEvent.TYPE, this::logEnemyDiedEvent); + } - private void logEnemyDiedEvent(EnemyDiedEvent event) { - log(String.format("%s has died with HP = %d", event.getEnemy().getName(), event.getEnemy().getHp())); - } + private void logHitEvent(HitEvent event) { + log(String.format("%s hits %s with damage = %d", event.getAttacker().getName(), event.getTarget().getName(), event.getDamage())); + } - @Override - public void update(float dt) { - super.update(dt); + private void log(String message) { + logger.add(message); + log.info(message); + logLbl.setText(logger.stream().collect(Collectors.joining("\n"))); + logVisibilityDuration = LOG_VISIBILITY_DURATION; + } - hp.setValue((float) player.getHp() / (float) player.getMaxHp()); + private void logEnemyDiedEvent(EnemyDiedEvent event) { + log(String.format("%s has died with HP = %d", event.getEnemy().getName(), event.getEnemy().getHp())); + } - if(logVisibilityDuration > 0) { - logVisibilityDuration -= dt * 1000; - } else { - logVisibilityDuration = 0; - } - } + @Override + public void update(float dt) { + super.update(dt); - @Override - public void draw(Screen screen, GUI gui) { - var coords = player.getCoordinates(); - var pos = player.getPosition(); - debugLbl.setText(String.format( - "FPS: %.2f\n" + - "Mem: %.2f / %.2f [MB]\n" + - "Coords: %d : %d\n" + - "Pos: %.2f : %.2f\n" + - "Entities: %d", - runner.instantFPS(), - runtime.totalMemory() / 1024f / 1024f, - runtime.maxMemory() / 1024f / 1024f, - coords.x(), coords.y(), - pos.x(), pos.y(), - player.getLayer().getEntities().size() - 1 - )); + hp.setValue((float) player.getHp() / (float) player.getMaxHp()); - logLbl.setAlpha(Math.min(1f, logVisibilityDuration / LOG_VISIBILITY_FADING_OUT)); + if (logVisibilityDuration > 0) { + logVisibilityDuration -= dt * 1000; + } else { + logVisibilityDuration = 0; + } - super.draw(screen, gui); - } + if (player.getWeapon() != null && player.getWeapon() != currentWeapon) { + weapon.setIcon(player.getWeapon().getIcon()); + this.currentWeapon = player.getWeapon(); + } else if (player.getWeapon() == null) { + this.currentWeapon = null; + } + } + + @Override + public void draw(Screen screen, GUI gui) { + var coords = player.getCoordinates(); + var pos = player.getPosition(); + debugLbl.setText(String.format("FPS: %.2f\n" + "Mem: %.2f / %.2f [MB]\n" + "Coords: %d : %d\n" + "Pos: %.2f : %.2f\n" + "Entities: %d", runner.instantFPS(), runtime.totalMemory() / 1024f / 1024f, runtime.maxMemory() / 1024f / 1024f, coords.x(), coords.y(), pos.x(), pos.y(), player.getLayer().getEntities().size() - 1)); + + logLbl.setAlpha(Math.min(1f, logVisibilityDuration / LOG_VISIBILITY_FADING_OUT)); + + super.draw(screen, gui); + } } \ No newline at end of file diff --git a/src/main/java/com/bartlomiejpluta/demo/runner/DemoRunner.java b/src/main/java/com/bartlomiejpluta/demo/runner/DemoRunner.java index 57e40a0..dac758e 100644 --- a/src/main/java/com/bartlomiejpluta/demo/runner/DemoRunner.java +++ b/src/main/java/com/bartlomiejpluta/demo/runner/DemoRunner.java @@ -1,122 +1,115 @@ package com.bartlomiejpluta.demo.runner; +import com.bartlomiejpluta.base.api.context.Context; +import com.bartlomiejpluta.base.api.gui.GUI; +import com.bartlomiejpluta.base.api.runner.GameRunner; +import com.bartlomiejpluta.base.api.screen.Screen; +import com.bartlomiejpluta.base.util.profiler.FPSProfiler; +import com.bartlomiejpluta.demo.entity.Player; +import com.bartlomiejpluta.demo.menu.MenuManager; +import com.bartlomiejpluta.demo.world.weapon.RangedWeapon; import lombok.*; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.bartlomiejpluta.base.api.context.Context; -import com.bartlomiejpluta.base.api.input.Input; -import com.bartlomiejpluta.base.api.screen.Screen; -import com.bartlomiejpluta.base.api.runner.GameRunner; -import com.bartlomiejpluta.base.api.gui.GUI; - -import com.bartlomiejpluta.base.util.profiler.FPSProfiler; - -import com.bartlomiejpluta.demo.map.ForrestTempleHandler; -import com.bartlomiejpluta.demo.entity.Player; -import com.bartlomiejpluta.demo.menu.MenuManager; - -import com.bartlomiejpluta.demo.world.weapon.*; - public class DemoRunner implements GameRunner { - private static final Logger log = LoggerFactory.getLogger(DemoRunner.class); - private Screen screen; - private Context context; - private MenuManager menu; - private GUI hud; + private static final Logger log = LoggerFactory.getLogger(DemoRunner.class); + private Screen screen; + private Context context; + private MenuManager menu; + private GUI hud; - @Getter - private Player player; + @Getter + private Player player; - private final FPSProfiler fpsProfiler = FPSProfiler.create(20); + private final FPSProfiler fpsProfiler = FPSProfiler.create(20); - @Override - public void init(Context context) { - this.context = context; - this.screen = context.getScreen(); + @Override + public void init(Context context) { + this.context = context; + this.screen = context.getScreen(); - configureScreen(); - configureCamera(); - initPlayer(); - initHUD(); - initMenu(); + configureScreen(); + configureCamera(); + initPlayer(); + initHUD(); + initMenu(); - menu.showStartMenu(); + menu.showStartMenu(); - screen.show(); - } + screen.show(); + } - private void configureScreen() { - var resolution = screen.getCurrentResolution(); - screen.setSize(1800, 1000); - screen.setPosition((resolution.x() - 1800)/2, (resolution.y() - 1000)/2); - } + private void configureScreen() { + var resolution = screen.getCurrentResolution(); + screen.setSize(1800, 1000); + screen.setPosition((resolution.x() - 1800) / 2, (resolution.y() - 1000) / 2); + } - private void configureCamera() { - context.getCamera().setScale(2f); - } + private void configureCamera() { + context.getCamera().setScale(2f); + } - private void initMenu() { - this.menu = new MenuManager(this, context); - } + private void initMenu() { + this.menu = new MenuManager(this, context); + } - private void initHUD() { - hud = context.newGUI(); - hud.hide(); - var hudComponent = hud.inflateComponent(A.widgets.hud.uid); - hud.setRoot(hudComponent); - } + private void initHUD() { + hud = context.newGUI(); + hud.hide(); + var hudComponent = hud.inflateComponent(A.widgets.hud.uid); + hud.setRoot(hudComponent); + } - private void initPlayer() { - this.player = new Player(context.createCharacter(A.charsets.luna.uid)); - } + private void initPlayer() { + this.player = new Player(context.createCharacter(A.charsets.luna.uid)); + } - private void resetPlayer() { - this.player.changeCharacterSet(A.charsets.luna.uid); - this.player.setScale(1f); - this.player.setSpeed(4f); - this.player.setAnimationSpeed(2f); - this.player.setBlocking(true); - this.player.setWeapon(new RangedWeapon("wooden_bow")); - } + private void resetPlayer() { + this.player.changeCharacterSet(A.charsets.luna.uid); + this.player.setScale(1f); + this.player.setSpeed(4f); + this.player.setAnimationSpeed(1f); + this.player.setBlocking(true); + this.player.setWeapon(new RangedWeapon("wooden_bow")); + } - public void newGame() { - menu.closeAll(); - menu.enableGameMenu(); - resetPlayer(); - context.openMap(A.maps.forrest.uid); - context.getMap().getObjectLayer(A.maps.forrest.layers.main).addEntity(this.player); - player.setCoordinates(5, 36); - context.resume(); - hud.show(); - } + public void newGame() { + menu.closeAll(); + menu.enableGameMenu(); + resetPlayer(); + context.openMap(A.maps.forrest.uid); + context.getMap().getObjectLayer(A.maps.forrest.layers.main).addEntity(this.player); + player.setCoordinates(5, 36); + context.resume(); + hud.show(); + } - public void returnToStartMenu() { - menu.closeAll(); - hud.hide(); - context.pause(); - context.closeMap(); - menu.disableGameMenu(); - menu.showStartMenu(); - } + public void returnToStartMenu() { + menu.closeAll(); + hud.hide(); + context.pause(); + context.closeMap(); + menu.disableGameMenu(); + menu.showStartMenu(); + } - public void exit() { - context.close(); - } + public void exit() { + context.close(); + } - public double instantFPS() { - return fpsProfiler.getInstantFPS(); - } + public double instantFPS() { + return fpsProfiler.getInstantFPS(); + } - @Override - public void update(float dt) { - fpsProfiler.update(dt); - } + @Override + public void update(float dt) { + fpsProfiler.update(dt); + } - @Override - public void dispose() { - // Do something after game loop is end - } + @Override + public void dispose() { + // Do something after game loop is end + } } \ No newline at end of file diff --git a/src/main/java/com/bartlomiejpluta/demo/world/weapon/MeleeWeapon.java b/src/main/java/com/bartlomiejpluta/demo/world/weapon/MeleeWeapon.java index 67958b6..206c7d4 100644 --- a/src/main/java/com/bartlomiejpluta/demo/world/weapon/MeleeWeapon.java +++ b/src/main/java/com/bartlomiejpluta/demo/world/weapon/MeleeWeapon.java @@ -1,65 +1,62 @@ package com.bartlomiejpluta.demo.world.weapon; +import com.bartlomiejpluta.base.api.context.*; +import com.bartlomiejpluta.base.api.icon.Icon; +import com.bartlomiejpluta.base.lib.animation.*; +import com.bartlomiejpluta.base.util.random.DiceRoller; +import com.bartlomiejpluta.demo.entity.Creature; +import com.bartlomiejpluta.demo.event.HitEvent; +import lombok.*; +import org.joml.Vector2i; + import java.util.Random; -import lombok.*; -import org.joml.Vector2i; -import com.bartlomiejpluta.base.api.context.*; -import com.bartlomiejpluta.base.lib.animation.*; -import com.bartlomiejpluta.base.util.random.DiceRoller; - -import com.bartlomiejpluta.demo.entity.Creature; - -import com.bartlomiejpluta.demo.event.HitEvent; - public class MeleeWeapon implements Weapon { - private final Random random = new Random(); - private final Context context; - private final DiceRoller roller; - private final AnimationRunner animation; - private final String sound; + private final Random random = new Random(); + private final Context context; + private final DiceRoller roller; + private final AnimationRunner animation; + private final String sound; - @Getter - private String name; + @Getter + private String name; - @Getter - private int cooldown; + @Getter + private final Icon icon; - public MeleeWeapon(@NonNull String id) { - this(DB.dao.melee_weapon.find(id)); - } + @Getter + private int cooldown; - public MeleeWeapon(@NonNull DB.model.MeleeWeaponModel template) { - this.context = ContextHolder.INSTANCE.getContext(); - this.name = template.getName(); - this.roller = DiceRoller.of(template.getDamage()); - this.cooldown = template.getCooldown(); - this.animation = new RandomAnimationsRunner(2) - .nRange(0, 2f) - .nScale(0.2f, 0.15f) - .uAnimationSpeed(0.5f, 1f) - .nRotation(0, 10) - .offset(0, -10) - .uDelay(250, 500) - .with(A.animations.get(template.getAnimation()).uid); - this.sound = A.sounds.get(template.getSound()).uid; - } + public MeleeWeapon(@NonNull String id) { + this(DB.dao.melee_weapon.find(id)); + } - @Override - 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 Creature) { - var character = (Creature) entity; - var damage = roller.roll(); - character.hit(attacker, damage); - animation.run(context, character.getLayer(), character); - context.playSound(sound); - context.fireEvent(new HitEvent(attacker, character, damage)); - return true; - } - } + public MeleeWeapon(@NonNull DB.model.MeleeWeaponModel template) { + this.context = ContextHolder.INSTANCE.getContext(); + this.name = template.getName(); + this.roller = DiceRoller.of(template.getDamage()); + this.cooldown = template.getCooldown(); + this.animation = new RandomAnimationsRunner(2).nRange(0, 2f).nScale(0.2f, 0.15f).uAnimationSpeed(0.5f, 1f).nRotation(0, 10).offset(0, -10).uDelay(250, 500).with(A.animations.get(template.getAnimation()).uid); + this.sound = A.sounds.get(template.getSound()).uid; + var icons = template.getIcon().split(","); + this.icon = context.createIcon(A.iconsets.get(icons[0]).uid, Integer.valueOf(icons[1]), Integer.valueOf(icons[2])); + } - return false; - } + @Override + 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 Creature) { + var character = (Creature) entity; + var damage = roller.roll(); + character.hit(attacker, damage); + animation.run(context, character.getLayer(), character); + context.playSound(sound); + context.fireEvent(new HitEvent(attacker, character, damage)); + return true; + } + } + + return false; + } } \ No newline at end of file diff --git a/src/main/java/com/bartlomiejpluta/demo/world/weapon/RangedWeapon.java b/src/main/java/com/bartlomiejpluta/demo/world/weapon/RangedWeapon.java index bd2d29f..a687d81 100644 --- a/src/main/java/com/bartlomiejpluta/demo/world/weapon/RangedWeapon.java +++ b/src/main/java/com/bartlomiejpluta/demo/world/weapon/RangedWeapon.java @@ -1,89 +1,81 @@ package com.bartlomiejpluta.demo.world.weapon; -import java.util.Random; - -import lombok.*; +import com.bartlomiejpluta.base.api.animation.Animation; import com.bartlomiejpluta.base.api.context.*; import com.bartlomiejpluta.base.api.entity.Entity; -import com.bartlomiejpluta.base.api.animation.Animation; +import com.bartlomiejpluta.base.api.icon.Icon; import com.bartlomiejpluta.base.api.move.*; import com.bartlomiejpluta.base.lib.animation.*; import com.bartlomiejpluta.base.util.random.DiceRoller; - import com.bartlomiejpluta.demo.entity.Creature; - import com.bartlomiejpluta.demo.event.HitEvent; +import lombok.*; + +import java.util.Random; public class RangedWeapon implements Weapon { - private final Random random = new Random(); - private final Context context; - private final DiceRoller dmgRoller; - private final DiceRoller rangeRoller; - private final BulletAnimationRunner animation; - private final String sound; - private final AnimationRunner punchAnimation; - private final String punchSound; - private final AnimationRunner missAnimation; - private final String missSound; + private final Random random = new Random(); + private final Context context; + private final DiceRoller dmgRoller; + private final DiceRoller rangeRoller; + private final BulletAnimationRunner animation; + private final String sound; + private final AnimationRunner punchAnimation; + private final String punchSound; + private final AnimationRunner missAnimation; + private final String missSound; - @Getter - private String name; + @Getter + private String name; - @Getter - private int cooldown; + @Getter + private final Icon icon; - public RangedWeapon(@NonNull String id) { - this(DB.dao.ranged_weapon.find(id)); - } + @Getter + private int cooldown; - public RangedWeapon(@NonNull DB.model.RangedWeaponModel template) { - this.context = ContextHolder.INSTANCE.getContext(); - this.name = template.getName(); - this.dmgRoller = DiceRoller.of(template.getDamage()); - this.rangeRoller = DiceRoller.of(template.getRange()); - this.cooldown = template.getCooldown(); - this.animation = new BulletAnimationRunner(A.animations.get(template.getAnimation()).uid) - .infinite() - .offset(0, -15) - .onHit(this::onHit) - .onMiss(this::onMiss) - .speed(7f) - .animationSpeed(4f) - .scale(0.6f); - 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 = A.sounds.get(template.getMissSound()).uid; - } + public RangedWeapon(@NonNull String id) { + this(DB.dao.ranged_weapon.find(id)); + } - private void onHit(Movable attacker, Entity 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); - context.playSound(punchSound); - context.fireEvent(new HitEvent(namedAttacker, character, damage)); - } - } + public RangedWeapon(@NonNull DB.model.RangedWeaponModel template) { + this.context = ContextHolder.INSTANCE.getContext(); + this.name = template.getName(); + this.dmgRoller = DiceRoller.of(template.getDamage()); + this.rangeRoller = DiceRoller.of(template.getRange()); + this.cooldown = template.getCooldown(); + this.animation = new BulletAnimationRunner(A.animations.get(template.getAnimation()).uid).infinite().offset(0, -15).onHit(this::onHit).onMiss(this::onMiss).speed(7f).animationSpeed(4f).scale(0.6f); + 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 = A.sounds.get(template.getMissSound()).uid; + var icons = template.getIcon().split(","); + this.icon = context.createIcon(A.iconsets.get(icons[0]).uid, Integer.valueOf(icons[1]), Integer.valueOf(icons[2])); + } - private void onMiss(Movable attacker, Animation animation) { - missAnimation.run(context, ((Creature) attacker).getLayer(), animation.getPosition()); - context.playSound(missSound); - } + private void onHit(Movable attacker, Entity 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); + context.playSound(punchSound); + context.fireEvent(new HitEvent(namedAttacker, character, damage)); + } + } - @Override - public boolean attack(Creature attacker) { - var direction = attacker.getFaceDirection(); - context.playSound(sound); - animation - .range(rangeRoller.roll()) - .direction(direction) - .rotation(direction.xAngle - 180) - .run(context, attacker.getLayer(), attacker); - return true; - } + private void onMiss(Movable attacker, Animation animation) { + missAnimation.run(context, ((Creature) attacker).getLayer(), animation.getPosition()); + context.playSound(missSound); + } + + @Override + public boolean attack(Creature attacker) { + var direction = attacker.getFaceDirection(); + context.playSound(sound); + animation.range(rangeRoller.roll()).direction(direction).rotation(direction.xAngle - 180).run(context, attacker.getLayer(), attacker); + return true; + } } \ No newline at end of file diff --git a/src/main/java/com/bartlomiejpluta/demo/world/weapon/Weapon.java b/src/main/java/com/bartlomiejpluta/demo/world/weapon/Weapon.java index 0007166..42782ec 100644 --- a/src/main/java/com/bartlomiejpluta/demo/world/weapon/Weapon.java +++ b/src/main/java/com/bartlomiejpluta/demo/world/weapon/Weapon.java @@ -1,9 +1,14 @@ package com.bartlomiejpluta.demo.world.weapon; +import com.bartlomiejpluta.base.api.icon.Icon; import com.bartlomiejpluta.demo.entity.Creature; public interface Weapon { - String getName(); - int getCooldown(); - boolean attack(Creature attacker); + String getName(); + + Icon getIcon(); + + int getCooldown(); + + boolean attack(Creature attacker); } \ No newline at end of file diff --git a/widgets/00bd0625-b3b8-4abf-97b7-91f42bce28ec.xml b/widgets/00bd0625-b3b8-4abf-97b7-91f42bce28ec.xml index 6daf65c..9e1425c 100644 --- a/widgets/00bd0625-b3b8-4abf-97b7-91f42bce28ec.xml +++ b/widgets/00bd0625-b3b8-4abf-97b7-91f42bce28ec.xml @@ -1,55 +1,50 @@ + xmlns:base="com.bartlomiejpluta.base.lib.gui" + xmlns:demo="com.bartlomiejpluta.demo.gui" + widthMode="SizeMode.RELATIVE" + heightMode="SizeMode.RELATIVE" + width="1f" + height="1f"> - + + + - + + + - + + + - - - - - - - - - - - + + + \ No newline at end of file diff --git a/widgets/56ca6b39-f949-4212-9c23-312db25887e0.xml b/widgets/56ca6b39-f949-4212-9c23-312db25887e0.xml index 5813d1b..2a78074 100644 --- a/widgets/56ca6b39-f949-4212-9c23-312db25887e0.xml +++ b/widgets/56ca6b39-f949-4212-9c23-312db25887e0.xml @@ -1,63 +1,67 @@ + xmlns:base="com.bartlomiejpluta.base.lib.gui" + xmlns:demo="com.bartlomiejpluta.demo.gui" + windowPosition="WindowPosition.CENTER" + margin="10f" + padding="20f"> - + - Game Menu + Game Menu + - + - Resume game + Resume game + - Back to start menu + Back to start menu + - Exit + Exit + - + - + \ No newline at end of file diff --git a/widgets/ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml b/widgets/ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml index b7e5750..06ee04e 100644 --- a/widgets/ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml +++ b/widgets/ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml @@ -1,53 +1,56 @@ + xmlns:base="com.bartlomiejpluta.base.lib.gui" + xmlns:demo="com.bartlomiejpluta.demo.gui" + windowPosition="WindowPosition.BOTTOM" + margin="10f" + padding="20f"> - + - Menu + Menu + - + - New Game + New Game + - Exit + Exit + - + - + \ No newline at end of file