From 3a406d85d5287d0ac3e8bc190ff4059b148e61f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 3 Dec 2014 14:59:49 +0100 Subject: ShotAnimation -> TankFireAnimation, shot.*. -> tank_fire*.* --- android/assets/data/shots.png | Bin 77414 -> 0 bytes android/assets/data/tank_fire.png | Bin 0 -> 77414 bytes android/assets/sounds/short_shot.mp3 | Bin 14209 -> 0 bytes android/assets/sounds/shot.mp3 | Bin 72306 -> 0 bytes android/assets/sounds/tank_fire.mp3 | Bin 0 -> 72306 bytes android/assets/sounds/tank_fire_short.mp3 | Bin 0 -> 14209 bytes core/src/ch/asynk/tankontank/TankOnTank.java | 12 +- .../engine/gfx/animations/ShotAnimation.java | 244 --------------------- .../engine/gfx/animations/TankFireAnimation.java | 244 +++++++++++++++++++++ core/src/ch/asynk/tankontank/game/Map.java | 16 +- 10 files changed, 258 insertions(+), 258 deletions(-) delete mode 100644 android/assets/data/shots.png create mode 100644 android/assets/data/tank_fire.png delete mode 100644 android/assets/sounds/short_shot.mp3 delete mode 100644 android/assets/sounds/shot.mp3 create mode 100644 android/assets/sounds/tank_fire.mp3 create mode 100644 android/assets/sounds/tank_fire_short.mp3 delete mode 100644 core/src/ch/asynk/tankontank/engine/gfx/animations/ShotAnimation.java create mode 100644 core/src/ch/asynk/tankontank/engine/gfx/animations/TankFireAnimation.java diff --git a/android/assets/data/shots.png b/android/assets/data/shots.png deleted file mode 100644 index 3d3c826..0000000 Binary files a/android/assets/data/shots.png and /dev/null differ diff --git a/android/assets/data/tank_fire.png b/android/assets/data/tank_fire.png new file mode 100644 index 0000000..3d3c826 Binary files /dev/null and b/android/assets/data/tank_fire.png differ diff --git a/android/assets/sounds/short_shot.mp3 b/android/assets/sounds/short_shot.mp3 deleted file mode 100644 index d958286..0000000 Binary files a/android/assets/sounds/short_shot.mp3 and /dev/null differ diff --git a/android/assets/sounds/shot.mp3 b/android/assets/sounds/shot.mp3 deleted file mode 100644 index 89406ad..0000000 Binary files a/android/assets/sounds/shot.mp3 and /dev/null differ diff --git a/android/assets/sounds/tank_fire.mp3 b/android/assets/sounds/tank_fire.mp3 new file mode 100644 index 0000000..89406ad Binary files /dev/null and b/android/assets/sounds/tank_fire.mp3 differ diff --git a/android/assets/sounds/tank_fire_short.mp3 b/android/assets/sounds/tank_fire_short.mp3 new file mode 100644 index 0000000..d958286 Binary files /dev/null and b/android/assets/sounds/tank_fire_short.mp3 differ diff --git a/core/src/ch/asynk/tankontank/TankOnTank.java b/core/src/ch/asynk/tankontank/TankOnTank.java index 44884c9..5b72827 100644 --- a/core/src/ch/asynk/tankontank/TankOnTank.java +++ b/core/src/ch/asynk/tankontank/TankOnTank.java @@ -56,12 +56,12 @@ public class TankOnTank extends Game manager.load("data/unit-overlays.atlas", TextureAtlas.class); manager.load("data/hex-overlays.atlas", TextureAtlas.class); manager.load("data/dice.png", Texture.class); - manager.load("data/shots.png", Texture.class); + manager.load("data/tank_fire.png", Texture.class); manager.load("data/explosions.png", Texture.class); manager.load("sounds/dice.mp3", Sound.class); manager.load("sounds/move.mp3", Sound.class); - manager.load("sounds/shot.mp3", Sound.class); - manager.load("sounds/short_shot.mp3", Sound.class); + manager.load("sounds/tank_fire.mp3", Sound.class); + manager.load("sounds/tank_fire_short.mp3", Sound.class); manager.load("sounds/explosion.mp3", Sound.class); manager.load("sounds/explosion_short.mp3", Sound.class); manager.load("sounds/promote.mp3", Sound.class); @@ -79,12 +79,12 @@ public class TankOnTank extends Game manager.unload("data/unit-overlays.atlas"); manager.unload("data/hex-overlays.atlas"); manager.unload("data/dice.png"); - manager.unload("data/shots.png"); + manager.unload("data/tank_fire.png"); manager.unload("data/explosions.png"); manager.unload("sounds/dice.mp3"); manager.unload("sounds/move.mp3"); - manager.unload("sounds/shot.mp3"); - manager.unload("sounds/short_shot.mp3"); + manager.unload("sounds/tank_fire.mp3"); + manager.unload("sounds/tank_fire_short.mp3"); manager.unload("sounds/explosion.mp3"); manager.unload("sounds/explosion_short.mp3"); manager.unload("sounds/promote.mp3"); diff --git a/core/src/ch/asynk/tankontank/engine/gfx/animations/ShotAnimation.java b/core/src/ch/asynk/tankontank/engine/gfx/animations/ShotAnimation.java deleted file mode 100644 index 0b2cce5..0000000 --- a/core/src/ch/asynk/tankontank/engine/gfx/animations/ShotAnimation.java +++ /dev/null @@ -1,244 +0,0 @@ -package ch.asynk.tankontank.engine.gfx.animations; - -import java.util.Random; - -import com.badlogic.gdx.utils.Disposable; -import com.badlogic.gdx.utils.Pool; - -import com.badlogic.gdx.audio.Sound; -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.TextureRegion; -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; - -import ch.asynk.tankontank.engine.gfx.Drawable; -import ch.asynk.tankontank.engine.gfx.Animation; - -public class ShotAnimation implements Disposable, Animation, Pool.Poolable -{ - private static final float SHOT_SCATTERING = 60f; - private static final float TIME_SCATTERING = 0.6f; - private static final float START_DELAY = 0.8f; - private static final float SHOT_SPEED = 700f; - private static final float EXPLOSION_FRAME_DURATION = 0.05f; - - private static Random random = new Random(); - private static Sound shotSnd; - private static Sound shotSndLong; - private static Sound explosionSnd; - private static Sound explosionSndLong; - private static Sprites shot; - private static Sprites explosion; - private static double shotSndLongId; - private static double explosionSndLongId; - - private TextureRegion shotRegion; - private float shot_a; - private float shot_x; - private float shot_y; - private float shot_w; - private float shot_dx; - private float shot_dy; - private float shot_dw; - - private float smoke_dx; - private float smoke_df; - private int smoke_frame; - - private float explosion_x; - private float explosion_y; - private float explosion_df; - private int explosion_frame; - - private boolean fired; - private boolean hit; - private float elapsed; - private float fire_time; - private float hit_time; - private float end_time; - - private float volume; - - private static final Pool shotAnimationPool = new Pool() { - @Override - protected ShotAnimation newObject() { - return new ShotAnimation(); - } - }; - - public static ShotAnimation get(float volume, float offset, float x0, float y0, float x1, float y1) - { - ShotAnimation a = shotAnimationPool.obtain(); - a.set(volume, offset, x0, y0, x1, y1); - return a; - } - - public static void init(Texture shot_texture, int scols, int srows, Texture explosion_texture, int ecols, int erows, Sound ls, Sound ss, Sound le, Sound se) - { - shotSndLong = ls; - shotSnd = ss; - explosionSndLong = le; - explosionSnd = se; - shot = new Sprites(shot_texture, scols, srows); - explosion = new Sprites(explosion_texture, ecols, erows); - shotSndLongId = -1; - explosionSndLongId = -1; - } - - public static void resetSound() - { - shotSndLongId = -1; - explosionSndLongId = -1; - } - - public static void free() - { - shotSnd.dispose(); - shotSndLong.dispose(); - explosionSnd.dispose(); - explosionSndLong.dispose(); - shot.dispose(); - explosion.dispose(); - } - - public ShotAnimation() - { - this.shotRegion = new TextureRegion(shot.frames[0]); - } - - private void set(float volume, float offset, float x0, float y0, float x1, float y1) - { - this.fired = false; - this.hit = false; - this.volume = volume; - - // shot geometry - y0 -= (shot.height / 2.0f); - x1 += ((SHOT_SCATTERING * random.nextFloat()) - (SHOT_SCATTERING / 2f)); - y1 += ((SHOT_SCATTERING * random.nextFloat()) - (SHOT_SCATTERING / 2f)); - - double r = Math.atan2((y0 - y1), (x0 - x1)); - float xadj = (float) (Math.cos(r) * offset); - float yadj = (float) (Math.sin(r) * offset); - x0 -= xadj; - y0 -= yadj; - - float a = (float) Math.toDegrees(r); - float dx = (x1 - x0); - float dy = (y1 - y0); - float w = (float) Math.sqrt((dx * dx) + (dy * dy)); - - // timing - float delay = START_DELAY + (random.nextFloat() * TIME_SCATTERING); - float shot_duration = ((random.nextFloat() * TIME_SCATTERING) + (w / SHOT_SPEED)); - float explosion_duration = (explosion.cols * EXPLOSION_FRAME_DURATION); - - this.elapsed = 0f; - this.fire_time = delay; - this.hit_time = (fire_time + shot_duration); - this.end_time = (hit_time + explosion_duration); - - // shot vars - this.shot_a = a; - this.shot_x = x0; - this.shot_y = y0; - this.shot_w = 0; - this.shot_dx = (dx / shot_duration); - this.shot_dy = (dy / shot_duration); - this.shot_dw = (w / shot_duration); - - // smoke var - this.smoke_dx = 0f; - this.smoke_df = (shot.rows / explosion_duration); - this.smoke_frame = 0; - - // explosion vars - this.explosion_x = (x1 - (explosion.width / 2.0f)); - this.explosion_y = (y1 - (explosion.height / 2.0f)); - this.explosion_df = (explosion.cols / explosion_duration); - this.explosion_frame = (random.nextInt(explosion.rows) * explosion.cols); - } - - @Override - public void reset() - { - } - - @Override - public void dispose() - { - shotAnimationPool.free(this); - } - - @Override - public boolean animate(float delta) - { - elapsed += delta; - - if (!fired && (elapsed < fire_time)) - return false; - - if (!fired) { - fired = true; - if (shotSndLongId == -1) - shotSndLongId = shotSndLong.play(volume); - else - shotSnd.play(volume); - } - - if (!hit && (elapsed < hit_time)) { - shot_w += (shot_dw * delta); - shot_x += (shot_dx * delta); - shot_y += (shot_dy * delta); - shotRegion.setRegionWidth((int) shot_w); - return false; - } - - if (!hit) { - hit = true; - if (explosionSndLongId == -1) - explosionSndLongId = explosionSndLong.play(volume); - else - explosionSnd.play(volume); - } - - if (elapsed < end_time) { - int frame = (int) ((elapsed - hit_time) * smoke_df); - if (frame != smoke_frame) { - smoke_frame = frame; - shotRegion.setRegion(shot.frames[smoke_frame]); - shotRegion.setRegionWidth((int) shot_w); - } - return false; - } - - return true; - } - - @Override - public void draw(Batch batch) - { - if (fired) - batch.draw(shotRegion, shot_x, shot_y, 0, 0, shotRegion.getRegionWidth(), shotRegion.getRegionHeight(), 1f, 1f, shot_a); - - if (hit) { - int frame = (explosion_frame + (int) ((elapsed - hit_time) * explosion_df)); - batch.draw(explosion.frames[frame], explosion_x, explosion_y); - } - } - - @Override - public void drawDebug(ShapeRenderer debugShapes) - { - debugShapes.end(); - debugShapes.begin(ShapeRenderer.ShapeType.Line); - debugShapes.identity(); - debugShapes.translate(shot_x, shot_y, 0); - debugShapes.rotate(0, 0, 1, shot_a); - debugShapes.translate(-shot_x, -shot_y, 0); - debugShapes.rect(shot_x, shot_y, shot_w, shot.height); - debugShapes.end(); - debugShapes.begin(ShapeRenderer.ShapeType.Line); - debugShapes.identity(); - } -} diff --git a/core/src/ch/asynk/tankontank/engine/gfx/animations/TankFireAnimation.java b/core/src/ch/asynk/tankontank/engine/gfx/animations/TankFireAnimation.java new file mode 100644 index 0000000..0bd6392 --- /dev/null +++ b/core/src/ch/asynk/tankontank/engine/gfx/animations/TankFireAnimation.java @@ -0,0 +1,244 @@ +package ch.asynk.tankontank.engine.gfx.animations; + +import java.util.Random; + +import com.badlogic.gdx.utils.Disposable; +import com.badlogic.gdx.utils.Pool; + +import com.badlogic.gdx.audio.Sound; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; + +import ch.asynk.tankontank.engine.gfx.Drawable; +import ch.asynk.tankontank.engine.gfx.Animation; + +public class TankFireAnimation implements Disposable, Animation, Pool.Poolable +{ + private static final float SHOT_SCATTERING = 60f; + private static final float TIME_SCATTERING = 0.6f; + private static final float START_DELAY = 0.8f; + private static final float SHOT_SPEED = 700f; + private static final float EXPLOSION_FRAME_DURATION = 0.05f; + + private static Random random = new Random(); + private static Sound fireSnd; + private static Sound fireSndLong; + private static Sound explosionSnd; + private static Sound explosionSndLong; + private static Sprites fire; + private static Sprites explosion; + private static double fireSndLongId; + private static double explosionSndLongId; + + private TextureRegion fireRegion; + private float fire_a; + private float fire_x; + private float fire_y; + private float fire_w; + private float fire_dx; + private float fire_dy; + private float fire_dw; + + private float smoke_dx; + private float smoke_df; + private int smoke_frame; + + private float explosion_x; + private float explosion_y; + private float explosion_df; + private int explosion_frame; + + private boolean fired; + private boolean hit; + private float elapsed; + private float fire_time; + private float hit_time; + private float end_time; + + private float volume; + + private static final Pool fireAnimationPool = new Pool() { + @Override + protected TankFireAnimation newObject() { + return new TankFireAnimation(); + } + }; + + public static TankFireAnimation get(float volume, float offset, float x0, float y0, float x1, float y1) + { + TankFireAnimation a = fireAnimationPool.obtain(); + a.set(volume, offset, x0, y0, x1, y1); + return a; + } + + public static void init(Texture fire_texture, int scols, int srows, Texture explosion_texture, int ecols, int erows, Sound ls, Sound ss, Sound le, Sound se) + { + fireSndLong = ls; + fireSnd = ss; + explosionSndLong = le; + explosionSnd = se; + fire = new Sprites(fire_texture, scols, srows); + explosion = new Sprites(explosion_texture, ecols, erows); + fireSndLongId = -1; + explosionSndLongId = -1; + } + + public static void resetSound() + { + fireSndLongId = -1; + explosionSndLongId = -1; + } + + public static void free() + { + fireSnd.dispose(); + fireSndLong.dispose(); + explosionSnd.dispose(); + explosionSndLong.dispose(); + fire.dispose(); + explosion.dispose(); + } + + public TankFireAnimation() + { + this.fireRegion = new TextureRegion(fire.frames[0]); + } + + private void set(float volume, float offset, float x0, float y0, float x1, float y1) + { + this.fired = false; + this.hit = false; + this.volume = volume; + + // fire geometry + y0 -= (fire.height / 2.0f); + x1 += ((SHOT_SCATTERING * random.nextFloat()) - (SHOT_SCATTERING / 2f)); + y1 += ((SHOT_SCATTERING * random.nextFloat()) - (SHOT_SCATTERING / 2f)); + + double r = Math.atan2((y0 - y1), (x0 - x1)); + float xadj = (float) (Math.cos(r) * offset); + float yadj = (float) (Math.sin(r) * offset); + x0 -= xadj; + y0 -= yadj; + + float a = (float) Math.toDegrees(r); + float dx = (x1 - x0); + float dy = (y1 - y0); + float w = (float) Math.sqrt((dx * dx) + (dy * dy)); + + // timing + float delay = START_DELAY + (random.nextFloat() * TIME_SCATTERING); + float fire_duration = ((random.nextFloat() * TIME_SCATTERING) + (w / SHOT_SPEED)); + float explosion_duration = (explosion.cols * EXPLOSION_FRAME_DURATION); + + this.elapsed = 0f; + this.fire_time = delay; + this.hit_time = (fire_time + fire_duration); + this.end_time = (hit_time + explosion_duration); + + // fire vars + this.fire_a = a; + this.fire_x = x0; + this.fire_y = y0; + this.fire_w = 0; + this.fire_dx = (dx / fire_duration); + this.fire_dy = (dy / fire_duration); + this.fire_dw = (w / fire_duration); + + // smoke var + this.smoke_dx = 0f; + this.smoke_df = (fire.rows / explosion_duration); + this.smoke_frame = 0; + + // explosion vars + this.explosion_x = (x1 - (explosion.width / 2.0f)); + this.explosion_y = (y1 - (explosion.height / 2.0f)); + this.explosion_df = (explosion.cols / explosion_duration); + this.explosion_frame = (random.nextInt(explosion.rows) * explosion.cols); + } + + @Override + public void reset() + { + } + + @Override + public void dispose() + { + fireAnimationPool.free(this); + } + + @Override + public boolean animate(float delta) + { + elapsed += delta; + + if (!fired && (elapsed < fire_time)) + return false; + + if (!fired) { + fired = true; + if (fireSndLongId == -1) + fireSndLongId = fireSndLong.play(volume); + else + fireSnd.play(volume); + } + + if (!hit && (elapsed < hit_time)) { + fire_w += (fire_dw * delta); + fire_x += (fire_dx * delta); + fire_y += (fire_dy * delta); + fireRegion.setRegionWidth((int) fire_w); + return false; + } + + if (!hit) { + hit = true; + if (explosionSndLongId == -1) + explosionSndLongId = explosionSndLong.play(volume); + else + explosionSnd.play(volume); + } + + if (elapsed < end_time) { + int frame = (int) ((elapsed - hit_time) * smoke_df); + if (frame != smoke_frame) { + smoke_frame = frame; + fireRegion.setRegion(fire.frames[smoke_frame]); + fireRegion.setRegionWidth((int) fire_w); + } + return false; + } + + return true; + } + + @Override + public void draw(Batch batch) + { + if (fired) + batch.draw(fireRegion, fire_x, fire_y, 0, 0, fireRegion.getRegionWidth(), fireRegion.getRegionHeight(), 1f, 1f, fire_a); + + if (hit) { + int frame = (explosion_frame + (int) ((elapsed - hit_time) * explosion_df)); + batch.draw(explosion.frames[frame], explosion_x, explosion_y); + } + } + + @Override + public void drawDebug(ShapeRenderer debugShapes) + { + debugShapes.end(); + debugShapes.begin(ShapeRenderer.ShapeType.Line); + debugShapes.identity(); + debugShapes.translate(fire_x, fire_y, 0); + debugShapes.rotate(0, 0, 1, fire_a); + debugShapes.translate(-fire_x, -fire_y, 0); + debugShapes.rect(fire_x, fire_y, fire_w, fire.height); + debugShapes.end(); + debugShapes.begin(ShapeRenderer.ShapeType.Line); + debugShapes.identity(); + } +} diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 74449f9..1693b75 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -18,7 +18,7 @@ import ch.asynk.tankontank.engine.PossiblePaths; import ch.asynk.tankontank.engine.gfx.Animation; import ch.asynk.tankontank.engine.gfx.animations.AnimationSequence; import ch.asynk.tankontank.engine.gfx.animations.DiceAnimation; -import ch.asynk.tankontank.engine.gfx.animations.ShotAnimation; +import ch.asynk.tankontank.engine.gfx.animations.TankFireAnimation; import ch.asynk.tankontank.engine.gfx.animations.PromoteAnimation; import ch.asynk.tankontank.engine.gfx.animations.SoundAnimation; import ch.asynk.tankontank.engine.gfx.animations.RunnableAnimation; @@ -93,11 +93,11 @@ public abstract class Map extends Board this.moveSound = game.manager.get("sounds/move.mp3", Sound.class); DiceAnimation.init(game.manager.get("data/dice.png", Texture.class), 16, 9, game.manager.get("sounds/dice.mp3", Sound.class)); PromoteAnimation.init(game.manager.get("data/hud.atlas", TextureAtlas.class), game.manager.get("sounds/promote.mp3", Sound.class)); - ShotAnimation.init( - game.manager.get("data/shots.png", Texture.class), 1, 7, + TankFireAnimation.init( + game.manager.get("data/tank_fire.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/short_shot.mp3", Sound.class), + game.manager.get("sounds/tank_fire.mp3", Sound.class), + game.manager.get("sounds/tank_fire_short.mp3", Sound.class), game.manager.get("sounds/explosion.mp3", Sound.class), game.manager.get("sounds/explosion_short.mp3", Sound.class) ); @@ -127,7 +127,7 @@ public abstract class Map extends Board moveSound.dispose(); DiceAnimation.free(); PromoteAnimation.free(); - ShotAnimation.free(); + TankFireAnimation.free(); } public void clearAll() @@ -402,12 +402,12 @@ public abstract class Map extends Board public void addEngagementAnimation(Unit target) { - ShotAnimation.resetSound(); + TankFireAnimation.resetSound(); Hex to = target.getHex(); for (Unit u : activatedUnits) { Hex from = u.getHex(); AnimationSequence seq = AnimationSequence.get(2); - seq.addAnimation(ShotAnimation.get(ctrl.cfg.fxVolume, (u.getWidth() / 2.f), from.getX(), from.getY(), to.getX(), to.getY())); + seq.addAnimation(TankFireAnimation.get(ctrl.cfg.fxVolume, (u.getWidth() / 2.f), from.getX(), from.getY(), to.getX(), to.getY())); seq.addAnimation(notifyDoneAnimation(target)); addAnimation(seq); } -- cgit v1.1-2-g2b99