feat(sounds): Added hurt sound

This commit is contained in:
Jakub Žitník 2025-03-28 15:41:25 +01:00
parent e58c7be90d
commit 94abddef81
Signed by: jzitnik
GPG Key ID: C577A802A6AF4EF3
5 changed files with 15 additions and 1 deletions

View File

@ -46,7 +46,7 @@ public class Sound {
var resources = annotation.resourceLocation();
var resource = resources[random.nextInt(resources.length)];
var typeVolume = anot.isAnnotationPresent(SoundTypeSet.class)
var typeVolume = anot == null ? 100 : anot.isAnnotationPresent(SoundTypeSet.class)
? anot.getAnnotation(SoundTypeSet.class).value().getVolume()
: 0;

View File

@ -8,4 +8,6 @@ public enum SoundKey {
GRAVEL_WALKING,
WOOD,
HURT,
}

View File

@ -0,0 +1,10 @@
package cz.jzitnik.game.core.sound.registry;
import cz.jzitnik.game.annotations.SoundRegistry;
import cz.jzitnik.game.core.sound.SoundKey;
@SoundRegistry(key = SoundKey.HURT, resourceLocation = {
"hurt.ogg",
})
public class HurtSound {
}

View File

@ -10,6 +10,7 @@ import java.util.List;
import cz.jzitnik.game.Game;
import cz.jzitnik.game.annotations.ReduceFallDamage;
import cz.jzitnik.game.core.reducefalldamage.Reducer;
import cz.jzitnik.game.core.sound.SoundKey;
import cz.jzitnik.tui.ScreenRenderer;
@Getter
@ -62,6 +63,7 @@ public class Player implements Serializable {
health = Math.max(0, health - amount);
if (amount != 0) {
game.playerHit(screenRenderer);
game.getGameStates().dependencies.sound.playSound(game.getConfiguration(), SoundKey.HURT, null);
}
if (health == 0) {

Binary file not shown.