diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Game.java b/SPD-classes/src/main/java/com/watabou/noosa/Game.java index 4348bddb0..4f8c820d4 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Game.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Game.java @@ -251,7 +251,8 @@ public class Game implements ApplicationListener { Game.realTime = TimeUtils.millis(); inputHandler.processAllEvents(); - + + Sample.INSTANCE.update(); scene.update(); Camera.updateAll(); } diff --git a/SPD-classes/src/main/java/com/watabou/noosa/audio/Sample.java b/SPD-classes/src/main/java/com/watabou/noosa/audio/Sample.java index e0049b43b..64ded2e2d 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/audio/Sample.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/audio/Sample.java @@ -23,8 +23,10 @@ package com.watabou.noosa.audio; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Sound; +import com.watabou.noosa.Game; import java.util.HashMap; +import java.util.HashSet; public enum Sample { @@ -42,6 +44,7 @@ public enum Sample { } ids.clear(); + delayedSFX.clear(); } @@ -104,6 +107,54 @@ public enum Sample { } } + private class DelayedSoundEffect{ + Object id; + float delay; + + float leftVol; + float rightVol; + float pitch; + } + + private static HashSet delayedSFX = new HashSet<>(); + + public void playDelayed( Object id, float delay ){ + playDelayed( id, delay, 1 ); + } + + public void playDelayed( Object id, float delay, float volume ) { + playDelayed( id, delay, volume, volume, 1 ); + } + + public void playDelayed( Object id, float delay, float volume, float pitch ) { + playDelayed( id, delay, volume, volume, pitch ); + } + + public synchronized void playDelayed( Object id, float delay, float leftVolume, float rightVolume, float pitch ) { + if (delay <= 0) { + play(id, leftVolume, rightVolume, pitch); + return; + } + DelayedSoundEffect sfx = new DelayedSoundEffect(); + sfx.id = id; + sfx.delay = delay; + sfx.leftVol = leftVolume; + sfx.rightVol = rightVolume; + sfx.pitch = pitch; + delayedSFX.add(sfx); + } + + public synchronized void update(){ + if (delayedSFX.isEmpty()) return; + for (DelayedSoundEffect sfx : delayedSFX.toArray(new DelayedSoundEffect[0])){ + sfx.delay -= Game.elapsed; + if (sfx.delay <= 0){ + delayedSFX.remove(sfx); + play(sfx.id, sfx.leftVol, sfx.rightVol, sfx.pitch); + } + } + } + public void enable( boolean value ) { enabled = value; } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java index baaee80f5..92a8bddad 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/mobs/Mob.java @@ -50,8 +50,10 @@ import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.TimekeepersHourg import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring; import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfWealth; import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfAggression; +import com.shatteredpixel.shatteredpixeldungeon.items.weapon.SpiritBow; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.enchantments.Lucky; import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.MissileWeapon; +import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart; import com.shatteredpixel.shatteredpixeldungeon.levels.Level; import com.shatteredpixel.shatteredpixeldungeon.levels.features.Chasm; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; @@ -546,7 +548,14 @@ public abstract class Mob extends Char { if (surprisedBy(enemy) && Dungeon.hero.canSurpriseAttack()) { Statistics.sneakAttacks++; Badges.validateRogueUnlock(); - Sample.INSTANCE.play(Assets.Sounds.HIT_STRONG); + //TODO this is somewhat messy, it would be nicer to not have to manually handle delays here + // playing the strong hit sound might work best as another property of weapon? + if (Dungeon.hero.belongings.weapon instanceof SpiritBow.SpiritArrow + || Dungeon.hero.belongings.weapon instanceof Dart){ + Sample.INSTANCE.playDelayed(Assets.Sounds.HIT_STRONG, 0.125f); + } else { + Sample.INSTANCE.play(Assets.Sounds.HIT_STRONG); + } if (enemy.buff(Preparation.class) != null) { Wound.hit(this); } else {