diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-26 23:35:26 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-26 23:35:26 +0100 |
commit | 777a0edf963f5ccc6854162fd178f282ff9edb47 (patch) | |
tree | 2525f9e845d7ac7fb93d1ad616a23435a8b1e8e1 | |
parent | a24609378b2dd5013e78552225d059cf8de48079 (diff) | |
download | RustAndDust-777a0edf963f5ccc6854162fd178f282ff9edb47.zip RustAndDust-777a0edf963f5ccc6854162fd178f282ff9edb47.tar.gz |
ShotAnimation: play only 1 long sound, reset in Map.animationsDone()
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/gfx/animations/ShotAnimation.java | 26 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Map.java | 4 |
2 files changed, 21 insertions, 9 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/gfx/animations/ShotAnimation.java b/core/src/ch/asynk/tankontank/engine/gfx/animations/ShotAnimation.java index 930570a..9879ed9 100644 --- a/core/src/ch/asynk/tankontank/engine/gfx/animations/ShotAnimation.java +++ b/core/src/ch/asynk/tankontank/engine/gfx/animations/ShotAnimation.java @@ -49,9 +49,11 @@ public class ShotAnimation implements Disposable, Animation, Pool.Poolable private static final float EXPLOSION_FRAME_DURATION = 0.05f; private static Random random = new Random(); - private static Sound sound; + private static Sound shortShot; + private static Sound longShot; private static Sprites shot; private static Sprites explosion; + private static double longShotId; private TextureRegion shotRegion; private float shot_a; @@ -79,7 +81,6 @@ public class ShotAnimation implements Disposable, Animation, Pool.Poolable private float end_time; private float volume; - private long soundId; private static final Pool<ShotAnimation> shotAnimationPool = new Pool<ShotAnimation>() { @Override @@ -95,16 +96,24 @@ public class ShotAnimation implements Disposable, Animation, Pool.Poolable return a; } - public static void init(Texture shot_texture, int scols, int srows, Texture explosion_texture, int ecols, int erows, Sound snd) + public static void init(Texture shot_texture, int scols, int srows, Texture explosion_texture, int ecols, int erows, Sound longSnd, Sound shortSnd) { - sound = snd; + longShot = longSnd; + shortShot = shortSnd; shot = new Sprites(shot_texture, scols, srows); explosion = new Sprites(explosion_texture, ecols, erows); + longShotId = -1; + } + + public static void resetAll() + { + longShotId = -1; } public static void free() { - sound.dispose(); + shortShot.dispose(); + longShot.dispose(); shot.texture.dispose(); explosion.texture.dispose(); } @@ -165,8 +174,6 @@ public class ShotAnimation implements Disposable, Animation, Pool.Poolable this.explosion_y = (y1 - (explosion.height / 2.0f)); this.explosion_df = (explosion.cols / explosion_duration); this.explosion_frame = (random.nextInt(explosion.rows) * explosion.cols); - - soundId = -1; } @Override @@ -190,7 +197,10 @@ public class ShotAnimation implements Disposable, Animation, Pool.Poolable if (!fired) { fired = true; - soundId = sound.play(volume); + if (longShotId == -1) + longShotId = longShot.play(volume); + else + shortShot.play(volume); } if (!hit && (elapsed < hit_time)) { diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 78a7b20..1209652 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -59,7 +59,8 @@ public abstract class Map extends Board ShotAnimation.init( game.manager.get("data/shots.png", Texture.class), 1, 7, game.manager.get("data/explosions.png", Texture.class), 16, 8, - game.manager.get("sounds/shot.mp3", Sound.class) + game.manager.get("sounds/shot.mp3", Sound.class), + game.manager.get("sounds/short_shot.mp3", Sound.class) ); setup(); @@ -189,6 +190,7 @@ public abstract class Map extends Board public void animationsDone() { + ShotAnimation.resetAll(); if (animationClosure != null) addAnimation(animationClosure); animationClosure = null; |