Add icons for weapons
This commit is contained in:
BIN
animations/0ddac391-4086-4e9c-8310-59db649419ff.png
Normal file
BIN
animations/0ddac391-4086-4e9c-8310-59db649419ff.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 28 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB |
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@@ -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.oggSword slashR\
|
$1311327d-4b74-4252-94da-23ee4129e357(1311327d-4b74-4252-94da-23ee4129e357.oggSword 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
|
||||||
|
|||||||
@@ -1,100 +1,98 @@
|
|||||||
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;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class HUD extends BorderLayout {
|
public class HUD extends BorderLayout {
|
||||||
private static final int MAX_LOG_SIZE = 10;
|
private static final int MAX_LOG_SIZE = 10;
|
||||||
private static final float LOG_VISIBILITY_DURATION = 8000f;
|
private static final float LOG_VISIBILITY_DURATION = 8000f;
|
||||||
private static final float LOG_VISIBILITY_FADING_OUT = 1000f;
|
private static final float LOG_VISIBILITY_FADING_OUT = 1000f;
|
||||||
private final DemoRunner runner;
|
private final DemoRunner runner;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final Runtime runtime;
|
private final Runtime runtime;
|
||||||
private LimitedQueue<String> logger = new LimitedQueue<>(MAX_LOG_SIZE);
|
private LimitedQueue<String> logger = new LimitedQueue<>(MAX_LOG_SIZE);
|
||||||
|
|
||||||
private float logVisibilityDuration = 0f;
|
private float logVisibilityDuration = 0f;
|
||||||
|
|
||||||
@Ref("hp")
|
private Weapon currentWeapon;
|
||||||
private Bar hp;
|
|
||||||
|
|
||||||
@Ref("debug")
|
@Ref("hp")
|
||||||
private Label debugLbl;
|
private Bar hp;
|
||||||
|
|
||||||
@Ref("log")
|
@Ref("debug")
|
||||||
private Label logLbl;
|
private Label debugLbl;
|
||||||
|
|
||||||
public HUD(Context context, GUI gui) {
|
@Ref("log")
|
||||||
super(context, gui);
|
private Label logLbl;
|
||||||
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 logHitEvent(HitEvent event) {
|
@Ref("weapon")
|
||||||
log(String.format("%s hits %s with damage = %d", event.getAttacker().getName(), event.getTarget().getName(), event.getDamage()));
|
private IconView weapon;
|
||||||
}
|
|
||||||
|
|
||||||
private void log(String message) {
|
public HUD(Context context, GUI gui) {
|
||||||
logger.add(message);
|
super(context, gui);
|
||||||
log.info(message);
|
this.runner = (DemoRunner) context.getGameRunner();
|
||||||
logLbl.setText(logger.stream().collect(Collectors.joining("\n")));
|
this.player = runner.getPlayer();
|
||||||
logVisibilityDuration = LOG_VISIBILITY_DURATION;
|
this.runtime = Runtime.getRuntime();
|
||||||
}
|
context.addEventListener(HitEvent.TYPE, this::logHitEvent);
|
||||||
|
context.addEventListener(EnemyDiedEvent.TYPE, this::logEnemyDiedEvent);
|
||||||
|
}
|
||||||
|
|
||||||
private void logEnemyDiedEvent(EnemyDiedEvent event) {
|
private void logHitEvent(HitEvent event) {
|
||||||
log(String.format("%s has died with HP = %d", event.getEnemy().getName(), event.getEnemy().getHp()));
|
log(String.format("%s hits %s with damage = %d", event.getAttacker().getName(), event.getTarget().getName(), event.getDamage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void log(String message) {
|
||||||
public void update(float dt) {
|
logger.add(message);
|
||||||
super.update(dt);
|
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) {
|
@Override
|
||||||
logVisibilityDuration -= dt * 1000;
|
public void update(float dt) {
|
||||||
} else {
|
super.update(dt);
|
||||||
logVisibilityDuration = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
hp.setValue((float) player.getHp() / (float) player.getMaxHp());
|
||||||
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));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,122 +1,115 @@
|
|||||||
package com.bartlomiejpluta.demo.runner;
|
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 lombok.*;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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 {
|
public class DemoRunner implements GameRunner {
|
||||||
private static final Logger log = LoggerFactory.getLogger(DemoRunner.class);
|
private static final Logger log = LoggerFactory.getLogger(DemoRunner.class);
|
||||||
private Screen screen;
|
private Screen screen;
|
||||||
private Context context;
|
private Context context;
|
||||||
private MenuManager menu;
|
private MenuManager menu;
|
||||||
private GUI hud;
|
private GUI hud;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private Player player;
|
private Player player;
|
||||||
|
|
||||||
private final FPSProfiler fpsProfiler = FPSProfiler.create(20);
|
private final FPSProfiler fpsProfiler = FPSProfiler.create(20);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Context context) {
|
public void init(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.screen = context.getScreen();
|
this.screen = context.getScreen();
|
||||||
|
|
||||||
configureScreen();
|
configureScreen();
|
||||||
configureCamera();
|
configureCamera();
|
||||||
initPlayer();
|
initPlayer();
|
||||||
initHUD();
|
initHUD();
|
||||||
initMenu();
|
initMenu();
|
||||||
|
|
||||||
menu.showStartMenu();
|
menu.showStartMenu();
|
||||||
|
|
||||||
screen.show();
|
screen.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
||||||
context.getCamera().setScale(2f);
|
context.getCamera().setScale(2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initMenu() {
|
private void initMenu() {
|
||||||
this.menu = new MenuManager(this, context);
|
this.menu = new MenuManager(this, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initHUD() {
|
private void initHUD() {
|
||||||
hud = context.newGUI();
|
hud = context.newGUI();
|
||||||
hud.hide();
|
hud.hide();
|
||||||
var hudComponent = hud.inflateComponent(A.widgets.hud.uid);
|
var hudComponent = hud.inflateComponent(A.widgets.hud.uid);
|
||||||
hud.setRoot(hudComponent);
|
hud.setRoot(hudComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPlayer() {
|
private void initPlayer() {
|
||||||
this.player = new Player(context.createCharacter(A.charsets.luna.uid));
|
this.player = new Player(context.createCharacter(A.charsets.luna.uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetPlayer() {
|
private void resetPlayer() {
|
||||||
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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void newGame() {
|
public void newGame() {
|
||||||
menu.closeAll();
|
menu.closeAll();
|
||||||
menu.enableGameMenu();
|
menu.enableGameMenu();
|
||||||
resetPlayer();
|
resetPlayer();
|
||||||
context.openMap(A.maps.forrest.uid);
|
context.openMap(A.maps.forrest.uid);
|
||||||
context.getMap().getObjectLayer(A.maps.forrest.layers.main).addEntity(this.player);
|
context.getMap().getObjectLayer(A.maps.forrest.layers.main).addEntity(this.player);
|
||||||
player.setCoordinates(5, 36);
|
player.setCoordinates(5, 36);
|
||||||
context.resume();
|
context.resume();
|
||||||
hud.show();
|
hud.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void returnToStartMenu() {
|
public void returnToStartMenu() {
|
||||||
menu.closeAll();
|
menu.closeAll();
|
||||||
hud.hide();
|
hud.hide();
|
||||||
context.pause();
|
context.pause();
|
||||||
context.closeMap();
|
context.closeMap();
|
||||||
menu.disableGameMenu();
|
menu.disableGameMenu();
|
||||||
menu.showStartMenu();
|
menu.showStartMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void exit() {
|
public void exit() {
|
||||||
context.close();
|
context.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double instantFPS() {
|
public double instantFPS() {
|
||||||
return fpsProfiler.getInstantFPS();
|
return fpsProfiler.getInstantFPS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float dt) {
|
public void update(float dt) {
|
||||||
fpsProfiler.update(dt);
|
fpsProfiler.update(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
// Do something after game loop is end
|
// Do something after game loop is end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,65 +1,62 @@
|
|||||||
package com.bartlomiejpluta.demo.world.weapon;
|
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 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 {
|
public class MeleeWeapon implements Weapon {
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final DiceRoller roller;
|
private final DiceRoller roller;
|
||||||
private final AnimationRunner animation;
|
private final AnimationRunner animation;
|
||||||
private final String sound;
|
private final String sound;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private int cooldown;
|
private final Icon icon;
|
||||||
|
|
||||||
public MeleeWeapon(@NonNull String id) {
|
@Getter
|
||||||
this(DB.dao.melee_weapon.find(id));
|
private int cooldown;
|
||||||
}
|
|
||||||
|
|
||||||
public MeleeWeapon(@NonNull DB.model.MeleeWeaponModel template) {
|
public MeleeWeapon(@NonNull String id) {
|
||||||
this.context = ContextHolder.INSTANCE.getContext();
|
this(DB.dao.melee_weapon.find(id));
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public MeleeWeapon(@NonNull DB.model.MeleeWeaponModel template) {
|
||||||
public boolean attack(Creature attacker) {
|
this.context = ContextHolder.INSTANCE.getContext();
|
||||||
var facingNeighbour = attacker.getCoordinates().add(attacker.getFaceDirection().vector, new Vector2i());
|
this.name = template.getName();
|
||||||
for(var entity : attacker.getLayer().getEntities()) {
|
this.roller = DiceRoller.of(template.getDamage());
|
||||||
if(entity.getCoordinates().equals(facingNeighbour) && entity.isBlocking() && entity instanceof Creature) {
|
this.cooldown = template.getCooldown();
|
||||||
var character = (Creature) entity;
|
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);
|
||||||
var damage = roller.roll();
|
this.sound = A.sounds.get(template.getSound()).uid;
|
||||||
character.hit(attacker, damage);
|
var icons = template.getIcon().split(",");
|
||||||
animation.run(context, character.getLayer(), character);
|
this.icon = context.createIcon(A.iconsets.get(icons[0]).uid, Integer.valueOf(icons[1]), Integer.valueOf(icons[2]));
|
||||||
context.playSound(sound);
|
}
|
||||||
context.fireEvent(new HitEvent(attacker, character, damage));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,89 +1,81 @@
|
|||||||
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();
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final DiceRoller dmgRoller;
|
private final DiceRoller dmgRoller;
|
||||||
private final DiceRoller rangeRoller;
|
private final DiceRoller rangeRoller;
|
||||||
private final BulletAnimationRunner animation;
|
private final BulletAnimationRunner animation;
|
||||||
private final String sound;
|
private final String sound;
|
||||||
private final AnimationRunner punchAnimation;
|
private final AnimationRunner punchAnimation;
|
||||||
private final String punchSound;
|
private final String punchSound;
|
||||||
private final AnimationRunner missAnimation;
|
private final AnimationRunner missAnimation;
|
||||||
private final String missSound;
|
private final String missSound;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private int cooldown;
|
private final Icon icon;
|
||||||
|
|
||||||
public RangedWeapon(@NonNull String id) {
|
@Getter
|
||||||
this(DB.dao.ranged_weapon.find(id));
|
private int cooldown;
|
||||||
}
|
|
||||||
|
|
||||||
public RangedWeapon(@NonNull DB.model.RangedWeaponModel template) {
|
public RangedWeapon(@NonNull String id) {
|
||||||
this.context = ContextHolder.INSTANCE.getContext();
|
this(DB.dao.ranged_weapon.find(id));
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onHit(Movable attacker, Entity target) {
|
public RangedWeapon(@NonNull DB.model.RangedWeaponModel template) {
|
||||||
if(target.isBlocking() && target instanceof Creature) {
|
this.context = ContextHolder.INSTANCE.getContext();
|
||||||
var namedAttacker = (Creature) attacker;
|
this.name = template.getName();
|
||||||
var character = (Creature) target;
|
this.dmgRoller = DiceRoller.of(template.getDamage());
|
||||||
var damage = dmgRoller.roll();
|
this.rangeRoller = DiceRoller.of(template.getRange());
|
||||||
character.hit(namedAttacker, damage);
|
this.cooldown = template.getCooldown();
|
||||||
punchAnimation.run(context, character.getLayer(), character);
|
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);
|
||||||
context.playSound(punchSound);
|
this.sound = A.sounds.get(template.getSound()).uid;
|
||||||
context.fireEvent(new HitEvent(namedAttacker, character, damage));
|
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) {
|
private void onHit(Movable attacker, Entity target) {
|
||||||
missAnimation.run(context, ((Creature) attacker).getLayer(), animation.getPosition());
|
if (target.isBlocking() && target instanceof Creature) {
|
||||||
context.playSound(missSound);
|
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
|
private void onMiss(Movable attacker, Animation animation) {
|
||||||
public boolean attack(Creature attacker) {
|
missAnimation.run(context, ((Creature) attacker).getLayer(), animation.getPosition());
|
||||||
var direction = attacker.getFaceDirection();
|
context.playSound(missSound);
|
||||||
context.playSound(sound);
|
}
|
||||||
animation
|
|
||||||
.range(rangeRoller.roll())
|
@Override
|
||||||
.direction(direction)
|
public boolean attack(Creature attacker) {
|
||||||
.rotation(direction.xAngle - 180)
|
var direction = attacker.getFaceDirection();
|
||||||
.run(context, attacker.getLayer(), attacker);
|
context.playSound(sound);
|
||||||
return true;
|
animation.range(rangeRoller.roll()).direction(direction).rotation(direction.xAngle - 180).run(context, attacker.getLayer(), attacker);
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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();
|
||||||
int getCooldown();
|
|
||||||
boolean attack(Creature attacker);
|
Icon getIcon();
|
||||||
|
|
||||||
|
int getCooldown();
|
||||||
|
|
||||||
|
boolean attack(Creature attacker);
|
||||||
}
|
}
|
||||||
@@ -1,55 +1,50 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<demo:HUD
|
<demo:HUD
|
||||||
xmlns:base="com.bartlomiejpluta.base.lib.gui"
|
xmlns:base="com.bartlomiejpluta.base.lib.gui"
|
||||||
xmlns:demo="com.bartlomiejpluta.demo.gui"
|
xmlns:demo="com.bartlomiejpluta.demo.gui"
|
||||||
widthMode="SizeMode.RELATIVE"
|
widthMode="SizeMode.RELATIVE"
|
||||||
heightMode="SizeMode.RELATIVE"
|
heightMode="SizeMode.RELATIVE"
|
||||||
width="1f"
|
width="1f"
|
||||||
height="1f">
|
height="1f">
|
||||||
|
|
||||||
<base:BorderLayout-TopLeft>
|
<base:BorderLayout-TopLeft>
|
||||||
|
<demo:Bar
|
||||||
|
ref="hp"
|
||||||
|
strokeColor="0x111111"
|
||||||
|
fillColor="0xFF0000"
|
||||||
|
widthMode="SizeMode.ABSOLUTE"
|
||||||
|
heightMode="SizeMode.ABSOLUTE"
|
||||||
|
width="250f"
|
||||||
|
height="20f"/>
|
||||||
|
</base:BorderLayout-TopLeft>
|
||||||
|
|
||||||
<demo:Bar
|
<base:BorderLayout-TopRight>
|
||||||
ref="hp"
|
<base:IconView ref="weapon" scale="2f"/>
|
||||||
strokeColor="0x111111"
|
</base:BorderLayout-TopRight>
|
||||||
fillColor="0xFF0000"
|
|
||||||
widthMode="SizeMode.ABSOLUTE"
|
|
||||||
heightMode="SizeMode.ABSOLUTE"
|
|
||||||
width="250f"
|
|
||||||
height="20f"
|
|
||||||
margin="5f" />
|
|
||||||
|
|
||||||
</base:BorderLayout-TopLeft>
|
<base:BorderLayout-BottomLeft>
|
||||||
|
<base:Label
|
||||||
|
ref="log"
|
||||||
|
font="A.fonts.roboto_regular.uid"
|
||||||
|
widthMode="SizeMode.ABSOLUTE"
|
||||||
|
width="400f"
|
||||||
|
height="25f"
|
||||||
|
alignment="GUI.ALIGN_BOTTOM | GUI.ALIGN_LEFT"
|
||||||
|
color="0xFFFFFF"
|
||||||
|
fontSize="15f"/>
|
||||||
|
</base:BorderLayout-BottomLeft>
|
||||||
|
|
||||||
<base:BorderLayout-BottomLeft>
|
<base:BorderLayout-BottomRight>
|
||||||
|
<base:Label
|
||||||
<base:Label
|
ref="debug"
|
||||||
ref="log"
|
font="A.fonts.roboto_regular.uid"
|
||||||
font=""2261c04f-b02e-4486-b388-8a0fa41622e9""
|
widthMode="SizeMode.ABSOLUTE"
|
||||||
widthMode="SizeMode.ABSOLUTE"
|
width="200f"
|
||||||
width="400f"
|
height="25f"
|
||||||
height="25f"
|
alignment="GUI.ALIGN_BOTTOM | GUI.ALIGN_RIGHT"
|
||||||
margin="10f"
|
color="0xFFFFFF"
|
||||||
alignment="GUI.ALIGN_BOTTOM | GUI.ALIGN_LEFT"
|
fontSize="15f"/>
|
||||||
color="0xFFFFFF"
|
</base:BorderLayout-BottomRight>
|
||||||
fontSize="15f"/>
|
|
||||||
|
|
||||||
</base:BorderLayout-BottomLeft>
|
|
||||||
|
|
||||||
<base:BorderLayout-BottomRight>
|
|
||||||
|
|
||||||
<base:Label
|
|
||||||
ref="debug"
|
|
||||||
font=""2261c04f-b02e-4486-b388-8a0fa41622e9""
|
|
||||||
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>
|
</demo:HUD>
|
||||||
@@ -1,63 +1,67 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<demo:GameMenuWindow
|
<demo:GameMenuWindow
|
||||||
xmlns:base="com.bartlomiejpluta.base.lib.gui"
|
xmlns:base="com.bartlomiejpluta.base.lib.gui"
|
||||||
xmlns:demo="com.bartlomiejpluta.demo.gui"
|
xmlns:demo="com.bartlomiejpluta.demo.gui"
|
||||||
windowPosition="WindowPosition.CENTER"
|
windowPosition="WindowPosition.CENTER"
|
||||||
margin="10f"
|
margin="10f"
|
||||||
padding="20f">
|
padding="20f">
|
||||||
|
|
||||||
<base:VLayout
|
<base:VLayout
|
||||||
width="200f"
|
width="200f"
|
||||||
widthMode="SizeMode.ABSOLUTE">
|
widthMode="SizeMode.ABSOLUTE">
|
||||||
|
|
||||||
<base:Label
|
<base:Label
|
||||||
font="A.fonts.roboto_regular.uid"
|
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"
|
||||||
red="1f"
|
red="1f"
|
||||||
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"
|
||||||
width="1f">
|
width="1f">
|
||||||
|
|
||||||
<demo:Button
|
<demo:Button
|
||||||
ref="resume_game"
|
ref="resume_game"
|
||||||
font="A.fonts.roboto_regular.uid"
|
font="A.fonts.roboto_regular.uid"
|
||||||
widthMode="SizeMode.RELATIVE"
|
widthMode="SizeMode.RELATIVE"
|
||||||
width="1f"
|
width="1f"
|
||||||
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"
|
||||||
font="A.fonts.roboto_regular.uid"
|
font="A.fonts.roboto_regular.uid"
|
||||||
widthMode="SizeMode.RELATIVE"
|
widthMode="SizeMode.RELATIVE"
|
||||||
width="1f"
|
width="1f"
|
||||||
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"
|
||||||
font="A.fonts.roboto_regular.uid"
|
font="A.fonts.roboto_regular.uid"
|
||||||
widthMode="SizeMode.RELATIVE"
|
widthMode="SizeMode.RELATIVE"
|
||||||
width="1f"
|
width="1f"
|
||||||
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>
|
||||||
|
|
||||||
</base:VLayout>
|
</base:VLayout>
|
||||||
|
|
||||||
</demo:GameMenuWindow>
|
</demo:GameMenuWindow>
|
||||||
@@ -1,53 +1,56 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<demo:StartMenuWindow
|
<demo:StartMenuWindow
|
||||||
xmlns:base="com.bartlomiejpluta.base.lib.gui"
|
xmlns:base="com.bartlomiejpluta.base.lib.gui"
|
||||||
xmlns:demo="com.bartlomiejpluta.demo.gui"
|
xmlns:demo="com.bartlomiejpluta.demo.gui"
|
||||||
windowPosition="WindowPosition.BOTTOM"
|
windowPosition="WindowPosition.BOTTOM"
|
||||||
margin="10f"
|
margin="10f"
|
||||||
padding="20f">
|
padding="20f">
|
||||||
|
|
||||||
<base:VLayout
|
<base:VLayout
|
||||||
width="200f"
|
width="200f"
|
||||||
widthMode="SizeMode.ABSOLUTE">
|
widthMode="SizeMode.ABSOLUTE">
|
||||||
|
|
||||||
<base:Label
|
<base:Label
|
||||||
font=""2261c04f-b02e-4486-b388-8a0fa41622e9""
|
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"
|
||||||
red="1f"
|
red="1f"
|
||||||
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"
|
||||||
width="1f">
|
width="1f">
|
||||||
|
|
||||||
<demo:Button
|
<demo:Button
|
||||||
ref="new_game"
|
ref="new_game"
|
||||||
font="A.fonts.roboto_regular.uid"
|
font="A.fonts.roboto_regular.uid"
|
||||||
widthMode="SizeMode.RELATIVE"
|
widthMode="SizeMode.RELATIVE"
|
||||||
width="1f"
|
width="1f"
|
||||||
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"
|
||||||
font="A.fonts.roboto_regular.uid"
|
font="A.fonts.roboto_regular.uid"
|
||||||
widthMode="SizeMode.RELATIVE"
|
widthMode="SizeMode.RELATIVE"
|
||||||
width="1f"
|
width="1f"
|
||||||
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>
|
||||||
|
|
||||||
</base:VLayout>
|
</base:VLayout>
|
||||||
|
|
||||||
</demo:StartMenuWindow>
|
</demo:StartMenuWindow>
|
||||||
Reference in New Issue
Block a user