Add sound and animations to melee weapon attack
This commit is contained in:
BIN
animations/61e67e44-a0cd-4210-8d1e-ccddcd62c78d.png
Normal file
BIN
animations/61e67e44-a0cd-4210-8d1e-ccddcd62c78d.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
BIN
audio/1311327d-4b74-4252-94da-23ee4129e357.ogg
Normal file
BIN
audio/1311327d-4b74-4252-94da-23ee4129e357.ogg
Normal file
Binary file not shown.
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@@ -8,4 +8,6 @@ $9da2c95b-45b7-49e5-957b-c1c8803cdf28(9da2c95b-45b7-49e5-957b-c1c8803cdf28.png
|
||||
$2261c04f-b02e-4486-b388-8a0fa41622e9(2261c04f-b02e-4486-b388-8a0fa41622e9.ttfRoboto RegularB\
|
||||
$ab9d40b4-eb28-45d7-bff2-9432a05eb41a(ab9d40b4-eb28-45d7-bff2-9432a05eb41a.xml
|
||||
Start MenuB[
|
||||
$56ca6b39-f949-4212-9c23-312db25887e0(56ca6b39-f949-4212-9c23-312db25887e0.xml Game Menu
|
||||
$56ca6b39-f949-4212-9c23-312db25887e0(56ca6b39-f949-4212-9c23-312db25887e0.xml Game MenuJ[
|
||||
$61e67e44-a0cd-4210-8d1e-ccddcd62c78d(61e67e44-a0cd-4210-8d1e-ccddcd62c78d.pngSlash (R]
|
||||
$1311327d-4b74-4252-94da-23ee4129e357(1311327d-4b74-4252-94da-23ee4129e357.oggSword slash
|
||||
@@ -20,6 +20,8 @@ public class MeleeWeaponDAO {
|
||||
.name(result.getString("name"))
|
||||
.damage(result.getString("damage"))
|
||||
.cooldown(result.getInt("cooldown"))
|
||||
.animation(result.getString("animation"))
|
||||
.sound(result.getString("sound"))
|
||||
.build();
|
||||
items.put(result.getString("id"), weapon);
|
||||
}
|
||||
|
||||
@@ -9,4 +9,6 @@ public class MeleeWeaponModel {
|
||||
private final String name;
|
||||
private final String damage;
|
||||
private final int cooldown;
|
||||
private final String animation;
|
||||
private final String sound;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import org.joml.Vector2i;
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.entity.Entity;
|
||||
import com.bartlomiejpluta.base.lib.entity.EntityDelegate;
|
||||
import com.bartlomiejpluta.base.lib.animation.AnimationRunner;
|
||||
|
||||
import com.bartlomiejpluta.demo.runner.DemoRunner;
|
||||
import com.bartlomiejpluta.demo.world.weapon.MeleeWeapon;
|
||||
@@ -60,6 +61,10 @@ public class Character extends EntityDelegate {
|
||||
hp -= dmg;
|
||||
}
|
||||
|
||||
public void runAnimation(AnimationRunner animationRunner) {
|
||||
animationRunner.run(context, getLayer(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
super.update(dt);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Enemy extends Character implements NPC {
|
||||
setSpeed(template.getSpeed());
|
||||
setAnimationSpeed(template.getAnimationSpeed());
|
||||
setBlocking(template.isBlocking());
|
||||
setWeapon(new MeleeWeapon(((DemoRunner) context.getGameRunner()).getMeleeWeaponDAO().get(template.getMeleeWeapon())));
|
||||
setWeapon(new MeleeWeapon(context, ((DemoRunner) context.getGameRunner()).getMeleeWeaponDAO().get(template.getMeleeWeapon())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -78,7 +78,7 @@ public class DemoRunner implements GameRunner {
|
||||
this.player.setAnimationSpeed(0.005f);
|
||||
this.player.setBlocking(true);
|
||||
this.player.setCoordinates(0, 11);
|
||||
this.player.setWeapon(new MeleeWeapon(meleeWeaponDAO.get("wooden_sword")));
|
||||
this.player.setWeapon(new MeleeWeapon(context, meleeWeaponDAO.get("wooden_sword")));
|
||||
}
|
||||
|
||||
public void newGame() {
|
||||
|
||||
@@ -3,13 +3,18 @@ package com.bartlomiejpluta.demo.world.weapon;
|
||||
import java.util.Random;
|
||||
|
||||
import lombok.*;
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.lib.animation.*;
|
||||
import com.bartlomiejpluta.demo.database.model.MeleeWeaponModel;
|
||||
import com.bartlomiejpluta.demo.entity.Character;
|
||||
import com.bartlomiejpluta.demo.util.DiceRoller;
|
||||
|
||||
public class MeleeWeapon {
|
||||
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;
|
||||
@@ -17,13 +22,24 @@ public class MeleeWeapon {
|
||||
@Getter
|
||||
private int cooldown;
|
||||
|
||||
public MeleeWeapon(MeleeWeaponModel template) {
|
||||
public MeleeWeapon(@NonNull Context context, @NonNull MeleeWeaponModel template) {
|
||||
this.context = context;
|
||||
this.name = template.getName();
|
||||
this.roller = DiceRoller.of(template.getDamage());
|
||||
this.cooldown = template.getCooldown();
|
||||
this.animation = new RandomAnimationsRunner(5)
|
||||
.nRange(0, 2f)
|
||||
.nScale(0.2f, 0.15f)
|
||||
.uAnimationSpeed(0.01f, 0.05f)
|
||||
.offset(0, -10)
|
||||
.uDelay(0, 500)
|
||||
.with(template.getAnimation());
|
||||
this.sound = template.getSound();
|
||||
}
|
||||
|
||||
public void attack(Character character) {
|
||||
character.hit(roller.roll());
|
||||
character.runAnimation(animation);
|
||||
context.playSound(sound);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user