From c7a5eade2b1f0bc168a6b31b9426c2b270972f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 10 Oct 2014 08:58:26 +0200 Subject: Pawn: add prevPosition, revertPosition(), getRevertLastMoveAnimation() --- core/src/ch/asynk/tankontank/engine/Pawn.java | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java index 15e4200..6fe1540 100644 --- a/core/src/ch/asynk/tankontank/engine/Pawn.java +++ b/core/src/ch/asynk/tankontank/engine/Pawn.java @@ -25,6 +25,7 @@ public abstract class Pawn implements Drawable, Disposable private static final float MOVE_TIME = 0.4f; private Vector3 position = new Vector3(0f, 0f, 0f); + private Vector3 prevPosition = new Vector3(0f, 0f, 0f); private Image image; private StackedImages overlays; @@ -70,6 +71,17 @@ public abstract class Pawn implements Drawable, Disposable return position; } + public Vector3 getPreviousPosition() + { + return prevPosition; + } + + private void revertPosition() + { + position.set(prevPosition); + prevPosition.set(0f, 0f, 0f); + } + public Vector2 getCenter() { float x = (image.getX() + (image.getWidth() / 2f)); @@ -160,8 +172,25 @@ public abstract class Pawn implements Drawable, Disposable return seq; } + public AnimationSequence getRevertLastMoveAnimation() + { + AnimationSequence seq = AnimationSequence.get(4); + seq.addAnimation(MoveToAnimation.get(this, prevPosition, MOVE_TIME)); + seq.addAnimation(RunnableAnimation.get(this, new Runnable() { + @Override + public void run() { + revertPosition(); + setPosition(position.x, position.y, position.z); + } + })); + + return seq; + } + public AnimationSequence getMoveAnimation(ArrayList path) { + prevPosition.set(position); + int s = path.size(); final Vector3 finalPos = path.get(s - 1); -- cgit v1.1-2-g2b99