diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-02-20 02:10:46 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-02-20 02:10:46 +0100 |
commit | efc2a97e12612f3ec515b1fe10c4151f1a1ccb17 (patch) | |
tree | 5bf9c440ea4da3f4b90b58444ae4111de0799613 /core/src | |
parent | 69dee7fd17f76397daa6e74eb6d78110aaa35201 (diff) | |
download | RustAndDust-efc2a97e12612f3ec515b1fe10c4151f1a1ccb17.zip RustAndDust-efc2a97e12612f3ec515b1fe10c4151f1a1ccb17.tar.gz |
Board: abstract animationsDone() called when animation list is emtpy
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 40 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Ctrl.java | 3 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Map.java | 41 |
3 files changed, 32 insertions, 52 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index e7e3105..b11eae4 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -103,7 +103,6 @@ public abstract class Board implements Disposable, Animation initSides(); this.selectedTile = selectedTile; - animations.add(selectedTile); } private void initSides() @@ -216,20 +215,16 @@ public abstract class Board implements Disposable, Animation return t; } + protected abstract void animationsOver(); + protected void addAnimation(Animation a) { - animationCount += 1; nextAnimations.add(a); } - protected void animationDone() - { - animationCount -= 1; - } - public int animationCount() { - return animationCount; + return animations.size(); } private void stats() @@ -241,11 +236,10 @@ public abstract class Board implements Disposable, Animation print = true; } - // FIXME this will never be false - // if (animationCount != animations.size()) { - // animationCount = animations.size(); - // print = true; - // } + if (animationCount != animations.size()) { + animationCount = animations.size(); + print = true; + } if (print) Gdx.app.debug("Board", " tiles:" + tileCount + " pawns:" + pawnCount + " animations:" + animationCount); @@ -253,18 +247,22 @@ public abstract class Board implements Disposable, Animation public boolean animate(float delta) { - + boolean over = (animations.size() > 0); Iterator<Animation> iter = animations.iterator(); while (iter.hasNext()) { Animation a = iter.next(); if (a.animate(delta)) iter.remove(); } + if (over && (animations.size() == 0)) + animationsOver(); for (int i = 0, n = nextAnimations.size(); i < n; i++) animations.add(nextAnimations.get(i)); nextAnimations.clear(); + selectedTile.animate(delta); + return true; } @@ -285,6 +283,8 @@ public abstract class Board implements Disposable, Animation while (animationIter.hasNext()) animationIter.next().draw(batch); + selectedTile.draw(batch); + if (transform) batch.setTransformMatrix(prevTransform); } @@ -445,14 +445,13 @@ public abstract class Board implements Disposable, Animation }); } - protected void movePawn(final Pawn pawn, Move move, RunnableAnimation whenDone, MoveToAnimationCb cb) + protected void movePawn(final Pawn pawn, Move move, MoveToAnimationCb cb) { pawn.move(move); removePawn(pawn); - AnimationSequence seq = pawn.getMoveAnimation(move.iterator(), (move.steps() + 2), cb); + AnimationSequence seq = pawn.getMoveAnimation(move.iterator(), (move.steps() + 1), cb); seq.addAnimation(getSetPawnOntoAnimation(pawn)); - seq.addAnimation(whenDone); addAnimation(seq); } @@ -462,19 +461,16 @@ public abstract class Board implements Disposable, Animation setPawnOnto(pawn, move.to, move.orientation); } - protected void revertLastPawnMove(final Pawn pawn, RunnableAnimation whenDone) + protected void revertLastPawnMove(final Pawn pawn) { removePawn(pawn); - AnimationSequence seq = pawn.getRevertLastMoveAnimation(2); - seq.addAnimation(RunnableAnimation.get(pawn, new Runnable() { + addAnimation(RunnableAnimation.get(pawn, new Runnable() { @Override public void run() { pushPawnOnto(pawn, pawn.getTile()); } })); - seq.addAnimation(whenDone); - addAnimation(seq); pawn.revertLastMove(); } diff --git a/core/src/ch/asynk/tankontank/game/Ctrl.java b/core/src/ch/asynk/tankontank/game/Ctrl.java index d4bd002..b410651 100644 --- a/core/src/ch/asynk/tankontank/game/Ctrl.java +++ b/core/src/ch/asynk/tankontank/game/Ctrl.java @@ -109,7 +109,8 @@ public class Ctrl implements Disposable { if (hud.dialogActive()) return; - leaveAnimationState(); + if (stateType == StateType.ANIMATION) + leaveAnimationState(); } private void leaveAnimationState() diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 2faa217..6be1a9c 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -261,12 +261,12 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS switch(move.type) { case REGULAR: initMove(unit); - movePawn(unit, move, notifyDoneAnimation(unit), this); + movePawn(unit, move, this); r = moveableUnits.size(); break; case EXIT: initMove(unit); - movePawn(unit, move, notifyDoneAnimation(unit), this); + movePawn(unit, move, this); ctrl.player.unitWithdraw(unit); r = moveableUnits.size(); break; @@ -300,7 +300,6 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS @Override public void run() { player.promote(unit); - animationDone(); } })); addAnimation(seq); @@ -395,7 +394,7 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS { for (Unit unit: activatedUnits) { TankOnTank.debug(" revertMove() " + unit); - revertLastPawnMove(unit, notifyDoneAnimation(unit)); + revertLastPawnMove(unit); commands.dispose(unit, Command.CommandType.MOVE); } activatedUnits.clear(); @@ -453,25 +452,15 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS soundId = sound.play(ctrl.cfg.fxVolume); } - private RunnableAnimation notifyDoneAnimation(final Unit unit) - { - return RunnableAnimation.get(unit, new Runnable() { - @Override - public void run() { - animationDone(); - } - }); - } - @Override - protected void animationDone() + protected void animationsOver() { - soundId = -1; - super.animationDone(); - if (animationCount() == 0) - ctrl.animationsOver(); - if (soundId >= 0) + if (soundId >= 0) { addAnimation( SoundAnimation.get(SoundAnimation.Action.FADE_OUT, sound, soundId, ctrl.cfg.fxVolume, 0.5f)); + soundId = -1; + return; + } + ctrl.animationsOver(); } private void addEngagementAnimation(Unit target) @@ -480,14 +469,11 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS Hex to = target.getHex(); for (Unit u : activatedUnits) { Hex from = u.getHex(); - AnimationSequence seq = AnimationSequence.get(2); float halfWidth = (u.getWidth() / 2f); if (u.isA(Unit.UnitType.INFANTRY)) - seq.addAnimation(InfantryFireAnimation.get(ctrl.cfg.fxVolume, from.getX(), from.getY(), to.getX(), to.getY(), halfWidth)); + addAnimation(InfantryFireAnimation.get(ctrl.cfg.fxVolume, from.getX(), from.getY(), to.getX(), to.getY(), halfWidth)); else - seq.addAnimation(TankFireAnimation.get(ctrl.cfg.fxVolume, from.getX(), from.getY(), to.getX(), to.getY(), halfWidth)); - seq.addAnimation(notifyDoneAnimation(target)); - addAnimation(seq); + addAnimation(TankFireAnimation.get(ctrl.cfg.fxVolume, from.getX(), from.getY(), to.getX(), to.getY(), halfWidth)); } } @@ -580,10 +566,7 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS unclaim(e.defender.getHex()); removePawn(e.defender); destroy.set(2f, e.defender); - AnimationSequence seq = AnimationSequence.get(2); - seq.addAnimation(destroy); - seq.addAnimation(notifyDoneAnimation(e.defender)); - addAnimation(seq); + addAnimation(destroy); } if ((activatedUnits.size() == 1) && e.attacker.isA(Unit.UnitType.AT_GUN) && e.defender.isHardTarget()) |