diff options
Diffstat (limited to 'core/src/sk/neuromancer/sphaera/rewrite/SoundPlayer.java')
| -rwxr-xr-x | core/src/sk/neuromancer/sphaera/rewrite/SoundPlayer.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/core/src/sk/neuromancer/sphaera/rewrite/SoundPlayer.java b/core/src/sk/neuromancer/sphaera/rewrite/SoundPlayer.java new file mode 100755 index 0000000..31db99c --- /dev/null +++ b/core/src/sk/neuromancer/sphaera/rewrite/SoundPlayer.java @@ -0,0 +1,75 @@ +package sk.neuromancer.sphaera.rewrite; + +import java.util.Random; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.audio.Sound; +import com.badlogic.gdx.utils.Disposable; + +import sk.neuromancer.sphaera.interf.Tickable; + +public class SoundPlayer implements Tickable, Disposable{ + + private Sound[] base = new Sound[4]; + private Sound explosion; + + public static final String BASE_SOUND_NAME = "base"; + + private boolean isLoaded = false; + private boolean isPlaying = false; + + public static final int BPM = 100; + public static final float TPB = (SphaeraGame.TPS * 60) / BPM; + + public static final float VOLUME = 0.2f; + + private int[] order = {3,2,0,1}; + + private int s = 0; + + public SoundPlayer() { + + } + + @Override + public void tick(long tickCount) { + if(!isPlaying) + return; + if(!isLoaded) + return; + if(tickCount % TPB == 0){ + base[order[s]].play(VOLUME); + s++; + s%=base.length; + } + } + + public void load() { + for(int i = 0; i < base.length; i++){ + base[i] = Gdx.audio.newSound(Gdx.files.internal(BASE_SOUND_NAME + i + ".wav")); + } + explosion = Gdx.audio.newSound(Gdx.files.internal("explosion.wav")); + isLoaded = true; + } + + public void play(){ + isPlaying = true; + } + + public void pause(){ + isPlaying = false; + } + + + public void playExplosion(){ + explosion.play(); + } + + @Override + public void dispose() { + for(Sound s: base){ + s.dispose(); + } + explosion.dispose(); + } +} |
