Add icons for weapons

This commit is contained in:
2022-08-24 23:14:21 +02:00
parent 60acb5749d
commit b157d7bf26
12 changed files with 422 additions and 435 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

View File

@@ -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 $ab9d40b4-eb28-45d7-bff2-9432a05eb41a(ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml
Start MenuB[ Start MenuB[
$56ca6b39-f949-4212-9c23-312db25887e0(56ca6b39-f949-4212-9c23-312db25887e0.xml Game MenuBU $56ca6b39-f949-4212-9c23-312db25887e0(56ca6b39-f949-4212-9c23-312db25887e0.xml Game MenuBU
$00bd0625-b3b8-4abf-97b7-91f42bce28ec(00bd0625-b3b8-4abf-97b7-91f42bce28ec.xmlHUDJ[ $00bd0625-b3b8-4abf-97b7-91f42bce28ec(00bd0625-b3b8-4abf-97b7-91f42bce28ec.xmlHUDJZ
$61e67e44-a0cd-4210-8d1e-ccddcd62c78d(61e67e44-a0cd-4210-8d1e-ccddcd62c78d.pngSlash (JZ
$e6f067f1-eba0-4e62-99c3-2fd867e6f142(e6f067f1-eba0-4e62-99c3-2fd867e6f142.pngPoof (J[ $e6f067f1-eba0-4e62-99c3-2fd867e6f142(e6f067f1-eba0-4e62-99c3-2fd867e6f142.pngPoof (J[
$312cc4e6-8c44-43e7-828a-e7e2a77836f3(312cc4e6-8c44-43e7-828a-e7e2a77836f3.pngArrow (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\ $1311327d-4b74-4252-94da-23ee4129e357(1311327d-4b74-4252-94da-23ee4129e357.ogg Sword slashR\
$e452e215-f581-40fe-a5cf-f555d3db83b8(e452e215-f581-40fe-a5cf-f555d3db83b8.ogg $e452e215-f581-40fe-a5cf-f555d3db83b8(e452e215-f581-40fe-a5cf-f555d3db83b8.ogg
Deku deathRW Deku deathRW

View File

@@ -1,19 +1,17 @@
package com.bartlomiejpluta.demo.gui; 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.context.Context;
import com.bartlomiejpluta.base.api.gui.*;
import com.bartlomiejpluta.base.api.input.*; 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.runner.DemoRunner;
import com.bartlomiejpluta.demo.entity.*;
import com.bartlomiejpluta.demo.event.*;
import com.bartlomiejpluta.demo.util.LimitedQueue; import com.bartlomiejpluta.demo.util.LimitedQueue;
import com.bartlomiejpluta.demo.world.weapon.Weapon;
import lombok.extern.slf4j.Slf4j;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -29,6 +27,8 @@ public class HUD extends BorderLayout {
private float logVisibilityDuration = 0f; private float logVisibilityDuration = 0f;
private Weapon currentWeapon;
@Ref("hp") @Ref("hp")
private Bar hp; private Bar hp;
@@ -38,6 +38,9 @@ public class HUD extends BorderLayout {
@Ref("log") @Ref("log")
private Label logLbl; private Label logLbl;
@Ref("weapon")
private IconView weapon;
public HUD(Context context, GUI gui) { public HUD(Context context, GUI gui) {
super(context, gui); super(context, gui);
this.runner = (DemoRunner) context.getGameRunner(); this.runner = (DemoRunner) context.getGameRunner();
@@ -68,30 +71,25 @@ public class HUD extends BorderLayout {
hp.setValue((float) player.getHp() / (float) player.getMaxHp()); hp.setValue((float) player.getHp() / (float) player.getMaxHp());
if(logVisibilityDuration > 0) { if (logVisibilityDuration > 0) {
logVisibilityDuration -= dt * 1000; logVisibilityDuration -= dt * 1000;
} else { } else {
logVisibilityDuration = 0; logVisibilityDuration = 0;
} }
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 @Override
public void draw(Screen screen, GUI gui) { public void draw(Screen screen, GUI gui) {
var coords = player.getCoordinates(); var coords = player.getCoordinates();
var pos = player.getPosition(); var pos = player.getPosition();
debugLbl.setText(String.format( 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));
"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)); logLbl.setAlpha(Math.min(1f, logVisibilityDuration / LOG_VISIBILITY_FADING_OUT));

View File

@@ -1,23 +1,16 @@
package com.bartlomiejpluta.demo.runner; package com.bartlomiejpluta.demo.runner;
import lombok.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.bartlomiejpluta.base.api.context.Context; 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.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.base.util.profiler.FPSProfiler;
import com.bartlomiejpluta.demo.map.ForrestTempleHandler;
import com.bartlomiejpluta.demo.entity.Player; import com.bartlomiejpluta.demo.entity.Player;
import com.bartlomiejpluta.demo.menu.MenuManager; import com.bartlomiejpluta.demo.menu.MenuManager;
import com.bartlomiejpluta.demo.world.weapon.RangedWeapon;
import com.bartlomiejpluta.demo.world.weapon.*; import lombok.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DemoRunner implements GameRunner { public class DemoRunner implements GameRunner {
@@ -51,7 +44,7 @@ public class DemoRunner implements GameRunner {
private void configureScreen() { private void configureScreen() {
var resolution = screen.getCurrentResolution(); var resolution = screen.getCurrentResolution();
screen.setSize(1800, 1000); screen.setSize(1800, 1000);
screen.setPosition((resolution.x() - 1800)/2, (resolution.y() - 1000)/2); screen.setPosition((resolution.x() - 1800) / 2, (resolution.y() - 1000) / 2);
} }
private void configureCamera() { private void configureCamera() {
@@ -77,7 +70,7 @@ public class DemoRunner implements GameRunner {
this.player.changeCharacterSet(A.charsets.luna.uid); this.player.changeCharacterSet(A.charsets.luna.uid);
this.player.setScale(1f); this.player.setScale(1f);
this.player.setSpeed(4f); this.player.setSpeed(4f);
this.player.setAnimationSpeed(2f); this.player.setAnimationSpeed(1f);
this.player.setBlocking(true); this.player.setBlocking(true);
this.player.setWeapon(new RangedWeapon("wooden_bow")); this.player.setWeapon(new RangedWeapon("wooden_bow"));
} }

View File

@@ -1,16 +1,15 @@
package com.bartlomiejpluta.demo.world.weapon; package com.bartlomiejpluta.demo.world.weapon;
import java.util.Random;
import lombok.*;
import org.joml.Vector2i;
import com.bartlomiejpluta.base.api.context.*; import com.bartlomiejpluta.base.api.context.*;
import com.bartlomiejpluta.base.api.icon.Icon;
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.Creature; import com.bartlomiejpluta.demo.entity.Creature;
import com.bartlomiejpluta.demo.event.HitEvent; import com.bartlomiejpluta.demo.event.HitEvent;
import lombok.*;
import org.joml.Vector2i;
import java.util.Random;
public class MeleeWeapon implements Weapon { public class MeleeWeapon implements Weapon {
private final Random random = new Random(); private final Random random = new Random();
@@ -22,6 +21,9 @@ public class MeleeWeapon implements Weapon {
@Getter @Getter
private String name; private String name;
@Getter
private final Icon icon;
@Getter @Getter
private int cooldown; private int cooldown;
@@ -34,22 +36,17 @@ public class MeleeWeapon implements Weapon {
this.name = template.getName(); this.name = template.getName();
this.roller = DiceRoller.of(template.getDamage()); this.roller = DiceRoller.of(template.getDamage());
this.cooldown = template.getCooldown(); this.cooldown = template.getCooldown();
this.animation = new RandomAnimationsRunner(2) 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);
.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; 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]));
} }
@Override @Override
public boolean attack(Creature 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 Creature) { if (entity.getCoordinates().equals(facingNeighbour) && entity.isBlocking() && entity instanceof Creature) {
var character = (Creature) entity; var character = (Creature) entity;
var damage = roller.roll(); var damage = roller.roll();
character.hit(attacker, damage); character.hit(attacker, damage);

View File

@@ -1,18 +1,17 @@
package com.bartlomiejpluta.demo.world.weapon; package com.bartlomiejpluta.demo.world.weapon;
import java.util.Random; import com.bartlomiejpluta.base.api.animation.Animation;
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.animation.Animation; import com.bartlomiejpluta.base.api.icon.Icon;
import com.bartlomiejpluta.base.api.move.*; 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.Creature; import com.bartlomiejpluta.demo.entity.Creature;
import com.bartlomiejpluta.demo.event.HitEvent; import com.bartlomiejpluta.demo.event.HitEvent;
import lombok.*;
import java.util.Random;
public class RangedWeapon implements Weapon { public class RangedWeapon implements Weapon {
private final Random random = new Random(); private final Random random = new Random();
@@ -29,6 +28,9 @@ public class RangedWeapon implements Weapon {
@Getter @Getter
private String name; private String name;
@Getter
private final Icon icon;
@Getter @Getter
private int cooldown; private int cooldown;
@@ -42,24 +44,18 @@ 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(A.animations.get(template.getAnimation()).uid) 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);
.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.sound = A.sounds.get(template.getSound()).uid;
this.punchAnimation = new SimpleAnimationRunner(A.animations.get(template.getPunchAnimation()).uid); this.punchAnimation = new SimpleAnimationRunner(A.animations.get(template.getPunchAnimation()).uid);
this.punchSound = A.sounds.get(template.getPunchSound()).uid; this.punchSound = A.sounds.get(template.getPunchSound()).uid;
this.missAnimation = new SimpleAnimationRunner(A.animations.get(template.getMissAnimation()).uid) this.missAnimation = new SimpleAnimationRunner(A.animations.get(template.getMissAnimation()).uid).scale(0.4f);
.scale(0.4f);
this.missSound = A.sounds.get(template.getMissSound()).uid; 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 onHit(Movable attacker, Entity target) { private void onHit(Movable attacker, Entity target) {
if(target.isBlocking() && target instanceof Creature) { if (target.isBlocking() && target instanceof Creature) {
var namedAttacker = (Creature) attacker; var namedAttacker = (Creature) attacker;
var character = (Creature) target; var character = (Creature) target;
var damage = dmgRoller.roll(); var damage = dmgRoller.roll();
@@ -79,11 +75,7 @@ public class RangedWeapon implements Weapon {
public boolean attack(Creature attacker) { public boolean attack(Creature attacker) {
var direction = attacker.getFaceDirection(); var direction = attacker.getFaceDirection();
context.playSound(sound); context.playSound(sound);
animation animation.range(rangeRoller.roll()).direction(direction).rotation(direction.xAngle - 180).run(context, attacker.getLayer(), attacker);
.range(rangeRoller.roll())
.direction(direction)
.rotation(direction.xAngle - 180)
.run(context, attacker.getLayer(), attacker);
return true; return true;
} }
} }

View File

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

View File

@@ -9,7 +9,6 @@
height="1f"> height="1f">
<base:BorderLayout-TopLeft> <base:BorderLayout-TopLeft>
<demo:Bar <demo:Bar
ref="hp" ref="hp"
strokeColor="0x111111" strokeColor="0x111111"
@@ -17,39 +16,35 @@
widthMode="SizeMode.ABSOLUTE" widthMode="SizeMode.ABSOLUTE"
heightMode="SizeMode.ABSOLUTE" heightMode="SizeMode.ABSOLUTE"
width="250f" width="250f"
height="20f" height="20f"/>
margin="5f" />
</base:BorderLayout-TopLeft> </base:BorderLayout-TopLeft>
<base:BorderLayout-BottomLeft> <base:BorderLayout-TopRight>
<base:IconView ref="weapon" scale="2f"/>
</base:BorderLayout-TopRight>
<base:BorderLayout-BottomLeft>
<base:Label <base:Label
ref="log" ref="log"
font="&quot;2261c04f-b02e-4486-b388-8a0fa41622e9&quot;" font="A.fonts.roboto_regular.uid"
widthMode="SizeMode.ABSOLUTE" widthMode="SizeMode.ABSOLUTE"
width="400f" width="400f"
height="25f" height="25f"
margin="10f"
alignment="GUI.ALIGN_BOTTOM | GUI.ALIGN_LEFT" alignment="GUI.ALIGN_BOTTOM | GUI.ALIGN_LEFT"
color="0xFFFFFF" color="0xFFFFFF"
fontSize="15f"/> fontSize="15f"/>
</base:BorderLayout-BottomLeft> </base:BorderLayout-BottomLeft>
<base:BorderLayout-BottomRight> <base:BorderLayout-BottomRight>
<base:Label <base:Label
ref="debug" ref="debug"
font="&quot;2261c04f-b02e-4486-b388-8a0fa41622e9&quot;" font="A.fonts.roboto_regular.uid"
widthMode="SizeMode.ABSOLUTE" widthMode="SizeMode.ABSOLUTE"
width="200f" width="200f"
height="25f" height="25f"
margin="10f"
alignment="GUI.ALIGN_BOTTOM | GUI.ALIGN_RIGHT" alignment="GUI.ALIGN_BOTTOM | GUI.ALIGN_RIGHT"
color="0xFFFFFF" color="0xFFFFFF"
fontSize="15f"/> fontSize="15f"/>
</base:BorderLayout-BottomRight> </base:BorderLayout-BottomRight>
</demo:HUD> </demo:HUD>

View File

@@ -20,7 +20,8 @@
green="1f" green="1f"
blue="1f" blue="1f"
alpha="0.5f" alpha="0.5f"
fontSize="30f">Game Menu</base:Label> fontSize="30f">Game Menu
</base:Label>
<base:VOptionChoice <base:VOptionChoice
widthMode="SizeMode.RELATIVE" widthMode="SizeMode.RELATIVE"
@@ -34,7 +35,8 @@
red="1f" red="1f"
green="1f" green="1f"
blue="1f" blue="1f"
fontSize="17f">Resume game</demo:Button> fontSize="17f">Resume game
</demo:Button>
<demo:Button <demo:Button
ref="start_menu" ref="start_menu"
@@ -44,7 +46,8 @@
red="1f" red="1f"
green="1f" green="1f"
blue="1f" blue="1f"
fontSize="17f">Back to start menu</demo:Button> fontSize="17f">Back to start menu
</demo:Button>
<demo:Button <demo:Button
ref="exit" ref="exit"
@@ -54,7 +57,8 @@
red="1f" red="1f"
green="1f" green="1f"
blue="1f" blue="1f"
fontSize="17f">Exit</demo:Button> fontSize="17f">Exit
</demo:Button>
</base:VOptionChoice> </base:VOptionChoice>

View File

@@ -12,7 +12,7 @@
widthMode="SizeMode.ABSOLUTE"> widthMode="SizeMode.ABSOLUTE">
<base:Label <base:Label
font="&quot;2261c04f-b02e-4486-b388-8a0fa41622e9&quot;" font="A.fonts.roboto_regular.uid"
widthMode="SizeMode.RELATIVE" widthMode="SizeMode.RELATIVE"
width="1f" width="1f"
alignment="GUI.ALIGN_TOP | GUI.ALIGN_CENTER" alignment="GUI.ALIGN_TOP | GUI.ALIGN_CENTER"
@@ -20,7 +20,8 @@
green="1f" green="1f"
blue="1f" blue="1f"
alpha="0.5f" alpha="0.5f"
fontSize="30f">Menu</base:Label> fontSize="30f">Menu
</base:Label>
<base:VOptionChoice <base:VOptionChoice
widthMode="SizeMode.RELATIVE" widthMode="SizeMode.RELATIVE"
@@ -34,7 +35,8 @@
red="1f" red="1f"
green="1f" green="1f"
blue="1f" blue="1f"
fontSize="17f">New Game</demo:Button> fontSize="17f">New Game
</demo:Button>
<demo:Button <demo:Button
ref="exit" ref="exit"
@@ -44,7 +46,8 @@
red="1f" red="1f"
green="1f" green="1f"
blue="1f" blue="1f"
fontSize="17f">Exit</demo:Button> fontSize="17f">Exit
</demo:Button>
</base:VOptionChoice> </base:VOptionChoice>