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
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

View File

@@ -1,19 +1,17 @@
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;
@@ -29,6 +27,8 @@ public class HUD extends BorderLayout {
private float logVisibilityDuration = 0f;
private Weapon currentWeapon;
@Ref("hp")
private Bar hp;
@@ -38,6 +38,9 @@ public class HUD extends BorderLayout {
@Ref("log")
private Label logLbl;
@Ref("weapon")
private IconView weapon;
public HUD(Context context, GUI gui) {
super(context, gui);
this.runner = (DemoRunner) context.getGameRunner();
@@ -73,25 +76,20 @@ public class HUD extends BorderLayout {
} else {
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
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
));
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));

View File

@@ -1,23 +1,16 @@
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.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.runner.GameRunner;
import com.bartlomiejpluta.base.api.screen.Screen;
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.*;
import com.bartlomiejpluta.demo.world.weapon.RangedWeapon;
import lombok.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DemoRunner implements GameRunner {
@@ -77,7 +70,7 @@ public class DemoRunner implements GameRunner {
this.player.changeCharacterSet(A.charsets.luna.uid);
this.player.setScale(1f);
this.player.setSpeed(4f);
this.player.setAnimationSpeed(2f);
this.player.setAnimationSpeed(1f);
this.player.setBlocking(true);
this.player.setWeapon(new RangedWeapon("wooden_bow"));
}

View File

@@ -1,16 +1,15 @@
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.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;
public class MeleeWeapon implements Weapon {
private final Random random = new Random();
@@ -22,6 +21,9 @@ public class MeleeWeapon implements Weapon {
@Getter
private String name;
@Getter
private final Icon icon;
@Getter
private int cooldown;
@@ -34,15 +36,10 @@ public class MeleeWeapon implements Weapon {
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.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]));
}
@Override

View File

@@ -1,18 +1,17 @@
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();
@@ -29,6 +28,9 @@ public class RangedWeapon implements Weapon {
@Getter
private String name;
@Getter
private final Icon icon;
@Getter
private int cooldown;
@@ -42,20 +44,14 @@ 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(A.animations.get(template.getAnimation()).uid)
.infinite()
.offset(0, -15)
.onHit(this::onHit)
.onMiss(this::onMiss)
.speed(7f)
.animationSpeed(4f)
.scale(0.6f);
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.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 onHit(Movable attacker, Entity target) {
@@ -79,11 +75,7 @@ public class RangedWeapon implements Weapon {
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);
animation.range(rangeRoller.roll()).direction(direction).rotation(direction.xAngle - 180).run(context, attacker.getLayer(), attacker);
return true;
}
}

View File

@@ -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();
Icon getIcon();
int getCooldown();
boolean attack(Creature attacker);
}

View File

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

View File

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

View File

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