From eae09d2d420e226795b08085afe2cc3c28cd6120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 29 Nov 2014 02:11:21 +0100 Subject: StatePromote,Map: set promote animation --- core/src/ch/asynk/tankontank/game/Map.java | 27 ++++++++++++++++++++++ .../asynk/tankontank/game/states/StatePromote.java | 11 ++++----- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index d0828ba..b059aab 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -17,9 +17,11 @@ 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.ShotAnimation; +import ch.asynk.tankontank.engine.gfx.animations.PromoteAnimation; import ch.asynk.tankontank.engine.gfx.animations.SoundAnimation; import ch.asynk.tankontank.engine.gfx.animations.RunnableAnimation; +import ch.asynk.tankontank.game.hud.Position; public abstract class Map extends Board { @@ -86,6 +88,7 @@ public abstract class Map extends Board super(game.factory, cfg, game.manager.get(textureName, Texture.class)); this.ctrl = game.ctrl; this.moveSound = game.manager.get("sounds/move.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, game.manager.get("data/explosions.png", Texture.class), 16, 8, @@ -118,6 +121,7 @@ public abstract class Map extends Board super.dispose(); clearAll(); moveSound.dispose(); + PromoteAnimation.free(); ShotAnimation.free(); } @@ -265,6 +269,29 @@ public abstract class Map extends Board activatedUnits.add(unit); } + public void promoteUnit(final Player player, final Unit unit, Position position) + { + activatedUnits.add(unit); + + // FIXME + float x = 60f; + float y = 60f; + if (position == Position.TOP_RIGHT) + x = getWidth() - 60f; + + Hex hex = unit.getHex(); + AnimationSequence seq = AnimationSequence.get(2); + seq.addAnimation(PromoteAnimation.get(x, y, hex.getX(), hex.getY(), ctrl.cfg.fxVolume)); + seq.addAnimation ( RunnableAnimation.get(unit, new Runnable() { + @Override + public void run() { + player.promote(unit); + animationDone(); + } + })); + addAnimation(seq); + } + public int moveUnit(Unit unit, Orientation o) { possiblePaths.orientation = o; diff --git a/core/src/ch/asynk/tankontank/game/states/StatePromote.java b/core/src/ch/asynk/tankontank/game/states/StatePromote.java index c6302f4..8cf557a 100644 --- a/core/src/ch/asynk/tankontank/game/states/StatePromote.java +++ b/core/src/ch/asynk/tankontank/game/states/StatePromote.java @@ -7,13 +7,10 @@ public class StatePromote extends StateCommon @Override public void enter(StateType prevState) { - ctrl.hud.actionButtons.hide(); - String str = selectedUnit.toString(); - if (ctrl.player.promote(selectedUnit)) { - map.activatedUnits.add(selectedUnit); - // ctrl.hud.notify(str+ " has been promoted"); - } - ctrl.setState(StateType.DONE); + map.promoteUnit(ctrl.player, selectedUnit, ctrl.battle.getHudPosition(ctrl.player)); + ctrl.setAnimationCount(1); + ctrl.setAfterAnimationState(StateType.SELECT); + ctrl.setState(StateType.ANIMATION); } @Override -- cgit v1.1-2-g2b99