v0.8.2: added delayed SFX functionality, used it to improve hit_strong
This commit is contained in:
parent
3dae7bf2cf
commit
a33fe02f53
|
@ -251,7 +251,8 @@ public class Game implements ApplicationListener {
|
|||
Game.realTime = TimeUtils.millis();
|
||||
|
||||
inputHandler.processAllEvents();
|
||||
|
||||
|
||||
Sample.INSTANCE.update();
|
||||
scene.update();
|
||||
Camera.updateAll();
|
||||
}
|
||||
|
|
|
@ -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<DelayedSoundEffect> 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;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user