From 777a0edf963f5ccc6854162fd178f282ff9edb47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 26 Nov 2014 23:35:26 +0100 Subject: ShotAnimation: play only 1 long sound, reset in Map.animationsDone() --- .../engine/gfx/animations/ShotAnimation.java | 26 +++++++++++++++------- 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 shotAnimationPool = new Pool() { @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; -- cgit v1.1-2-g2b99