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/ch/asynk/tankontank/engine | |
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/ch/asynk/tankontank/engine')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 40 |
1 files changed, 18 insertions, 22 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(); } |