From f42de5230fedee63bc0783f26822790bbba82dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 21 Sep 2014 02:09:32 +0200 Subject: PawnNode -> PawnImage does not implement Node anymore --- core/src/ch/asynk/tankontank/engine/Pawn.java | 5 +- core/src/ch/asynk/tankontank/engine/PawnImage.java | 70 ++++++++++++++++++++++ core/src/ch/asynk/tankontank/engine/PawnNode.java | 70 ---------------------- core/src/ch/asynk/tankontank/game/Unit.java | 4 +- 4 files changed, 75 insertions(+), 74 deletions(-) create mode 100644 core/src/ch/asynk/tankontank/engine/PawnImage.java delete mode 100644 core/src/ch/asynk/tankontank/engine/PawnNode.java diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java index 87c06c9..0198302 100644 --- a/core/src/ch/asynk/tankontank/engine/Pawn.java +++ b/core/src/ch/asynk/tankontank/engine/Pawn.java @@ -1,11 +1,12 @@ package ch.asynk.tankontank.engine; import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.utils.Disposable; -import ch.asynk.tankontank.engine.gfx.Node; +import ch.asynk.tankontank.engine.gfx.Drawable; import ch.asynk.tankontank.engine.gfx.animations.AnimationSequence; -public interface Pawn extends Node +public interface Pawn extends Drawable, Disposable { public Vector3 getLastPosition(); diff --git a/core/src/ch/asynk/tankontank/engine/PawnImage.java b/core/src/ch/asynk/tankontank/engine/PawnImage.java new file mode 100644 index 0000000..ac4a071 --- /dev/null +++ b/core/src/ch/asynk/tankontank/engine/PawnImage.java @@ -0,0 +1,70 @@ +package ch.asynk.tankontank.engine; + +import java.util.ArrayDeque; + +import com.badlogic.gdx.graphics.g2d.TextureRegion; + +import com.badlogic.gdx.math.Vector3; + +import ch.asynk.tankontank.engine.gfx.Image; +import ch.asynk.tankontank.engine.gfx.animations.MoveToAnimation; +import ch.asynk.tankontank.engine.gfx.animations.RunnableAnimation; +import ch.asynk.tankontank.engine.gfx.animations.AnimationSequence; + +public class PawnImage extends Image implements Pawn +{ + private static final float MOVE_TIME = 0.3f; + + private ArrayDeque path = new ArrayDeque(); + + public PawnImage(TextureRegion region) + { + super(region); + } + + @Override + public Vector3 getLastPosition() + { + if ((path == null) || (path.size() == 0)) return null; + return path.getFirst(); + } + + @Override + public void moveDone() + { + Vector3 v = path.pop(); + path.clear(); + path.push(v); + } + + @Override + public void pushMove(float x, float y, Pawn.Orientation o) + { + float r = ((o == Pawn.Orientation.KEEP) ? getRotation() : o.v); + setPosition(x, y, r); + Vector3 v = new Vector3(x, y, r); + if ((path.size() == 0) || (!v.equals(path.getFirst()))) + path.push(new Vector3(x, y, r)); + } + + @Override + public AnimationSequence getResetMovesAnimation() + { + final Vector3 finalPos = path.getLast(); + + AnimationSequence seq = AnimationSequence.get(path.size() + 1); + + while(path.size() != 0) { + seq.addAnimation(MoveToAnimation.get(this, path.pop(), MOVE_TIME)); + } + + seq.addAnimation(RunnableAnimation.get(new Runnable() { + @Override + public void run() { + path.push(finalPos); + } + })); + + return seq; + } +} diff --git a/core/src/ch/asynk/tankontank/engine/PawnNode.java b/core/src/ch/asynk/tankontank/engine/PawnNode.java deleted file mode 100644 index e095042..0000000 --- a/core/src/ch/asynk/tankontank/engine/PawnNode.java +++ /dev/null @@ -1,70 +0,0 @@ -package ch.asynk.tankontank.engine; - -import java.util.ArrayDeque; - -import com.badlogic.gdx.graphics.g2d.TextureRegion; - -import com.badlogic.gdx.math.Vector3; - -import ch.asynk.tankontank.engine.gfx.Image; -import ch.asynk.tankontank.engine.gfx.animations.MoveToAnimation; -import ch.asynk.tankontank.engine.gfx.animations.RunnableAnimation; -import ch.asynk.tankontank.engine.gfx.animations.AnimationSequence; - -public class PawnNode extends Image implements Pawn -{ - private static final float MOVE_TIME = 0.3f; - - private ArrayDeque path = new ArrayDeque(); - - public PawnNode(TextureRegion region) - { - super(region); - } - - @Override - public Vector3 getLastPosition() - { - if ((path == null) || (path.size() == 0)) return null; - return path.getFirst(); - } - - @Override - public void moveDone() - { - Vector3 v = path.pop(); - path.clear(); - path.push(v); - } - - @Override - public void pushMove(float x, float y, Pawn.Orientation o) - { - float r = ((o == Pawn.Orientation.KEEP) ? getRotation() : o.v); - setPosition(x, y, r); - Vector3 v = new Vector3(x, y, r); - if ((path.size() == 0) || (!v.equals(path.getFirst()))) - path.push(new Vector3(x, y, r)); - } - - @Override - public AnimationSequence getResetMovesAnimation() - { - final Vector3 finalPos = path.getLast(); - - AnimationSequence seq = AnimationSequence.get(path.size() + 1); - - while(path.size() != 0) { - seq.addAnimation(MoveToAnimation.get(this, path.pop(), MOVE_TIME)); - } - - seq.addAnimation(RunnableAnimation.get(new Runnable() { - @Override - public void run() { - path.push(finalPos); - } - })); - - return seq; - } -} diff --git a/core/src/ch/asynk/tankontank/game/Unit.java b/core/src/ch/asynk/tankontank/game/Unit.java index 310ead9..61833eb 100644 --- a/core/src/ch/asynk/tankontank/game/Unit.java +++ b/core/src/ch/asynk/tankontank/game/Unit.java @@ -2,9 +2,9 @@ package ch.asynk.tankontank.game; import com.badlogic.gdx.graphics.g2d.TextureRegion; -import ch.asynk.tankontank.engine.PawnNode; +import ch.asynk.tankontank.engine.PawnImage; -public class Unit extends PawnNode +public class Unit extends PawnImage { public int rng; public int def; -- cgit v1.1-2-g2b99