From 0cada9e6834eb7013546a0a738940007712b646e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 4 Oct 2014 15:40:55 +0200 Subject: Pawn: implements Disposable, cleanup - add +Vector3 position - add getPosition() - add getRotation() - add setRotation(float); - removes moves stack for now --- core/src/ch/asynk/tankontank/engine/Pawn.java | 135 ++++++++++---------------- 1 file changed, 53 insertions(+), 82 deletions(-) diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java index 446c3cd..52af8ca 100644 --- a/core/src/ch/asynk/tankontank/engine/Pawn.java +++ b/core/src/ch/asynk/tankontank/engine/Pawn.java @@ -24,9 +24,9 @@ public abstract class Pawn implements Drawable, Disposable { private static final float MOVE_TIME = 0.4f; + private Vector3 position = new Vector3(0f, 0f, 0f); private Image image; private StackedImages overlays; - private ArrayDeque moves = new ArrayDeque(); public abstract int getMovementPoints(); public abstract int getRoadMarchBonus(); @@ -46,10 +46,15 @@ public abstract class Pawn implements Drawable, Disposable this.overlays = new StackedImages(atlas); } - public Vector3 getLastPosition() + @Override + public void dispose() { - if ((moves == null) || (moves.size() == 0)) return null; - return moves.getFirst(); + image.dispose(); + } + + public Vector3 getPosition() + { + return position; } public Vector2 getCenter() @@ -70,80 +75,6 @@ public abstract class Pawn implements Drawable, Disposable return pos; } - public Orientation getOrientation() - { - return Orientation.fromRotation(getRotation()); - } - - public void moveDone() - { - Vector3 v = moves.pop(); - moves.clear(); - moves.push(v); - } - - public void pushMove(float x, float y, Orientation o) - { - float r = ((o == Orientation.KEEP) ? getRotation() : o.r()); - setPosition(x, y, r); - Vector3 v = new Vector3(x, y, r); - if ((moves.size() == 0) || (!v.equals(moves.getFirst()))) - moves.push(new Vector3(x, y, r)); - } - - public AnimationSequence getResetMovesAnimation() - { - final Vector3 finalPos = moves.getLast(); - - AnimationSequence seq = AnimationSequence.get(moves.size() + 1); - - while(moves.size() != 0) { - seq.addAnimation(MoveToAnimation.get(this, moves.pop(), MOVE_TIME)); - } - - seq.addAnimation(RunnableAnimation.get(this, new Runnable() { - @Override - public void run() { - moves.push(finalPos); - } - })); - - return seq; - } - - public AnimationSequence getMoveAnimation(Vector path) - { - int s = path.size(); - final Vector3 finalPos = path.get(s - 1); - - AnimationSequence seq = AnimationSequence.get(s + 1); - - for (Vector3 v : path) { - seq.addAnimation(MoveToAnimation.get(this, v, MOVE_TIME)); - } - - seq.addAnimation(RunnableAnimation.get(this, new Runnable() { - @Override - public void run() { - moves.push(finalPos); - } - })); - - return seq; - } - - public boolean hasOverlayEnabled() - { - return overlays.isEnabled(); - } - - public boolean enableOverlay(int i, boolean enable) - { - overlays.enable(i, enable); - if (enable) return true; - return hasOverlayEnabled(); - } - public float getX() { return image.getX(); @@ -169,24 +100,64 @@ public abstract class Pawn implements Drawable, Disposable return image.getRotation(); } + public Orientation getOrientation() + { + return Orientation.fromRotation(getRotation()); + } + public void setPosition(float x, float y) { + position.set(x, y, 0f); image.setPosition(x, y); float cx = x + (getWidth() / 2f); float cy = y + (getHeight() / 2f); overlays.centerOn(cx, cy); } + public void setRotation(float z) + { + position.z = z; + image.setRotation(z); + overlays.setRotation(z); + } + public void setPosition(float x, float y, float z) { setPosition(x, y); - overlays.setRotation(z); + setRotation(z); } - @Override - public void dispose() + public boolean hasOverlayEnabled() { - image.dispose(); + return overlays.isEnabled(); + } + + public boolean enableOverlay(int i, boolean enable) + { + overlays.enable(i, enable); + if (enable) return true; + return hasOverlayEnabled(); + } + + public AnimationSequence getMoveAnimation(Vector path) + { + int s = path.size(); + final Vector3 finalPos = path.get(s - 1); + + AnimationSequence seq = AnimationSequence.get(s + 1); + + for (Vector3 v : path) { + seq.addAnimation(MoveToAnimation.get(this, v, MOVE_TIME)); + } + + seq.addAnimation(RunnableAnimation.get(this, new Runnable() { + @Override + public void run() { + setPosition(finalPos.x, finalPos.y, finalPos.z); + } + })); + + return seq; } @Override -- cgit v1.1-2-g2b99