summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/Path.java85
1 files changed, 85 insertions, 0 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/Path.java b/core/src/ch/asynk/gdx/boardgame/Path.java
new file mode 100644
index 0000000..5bc46c3
--- /dev/null
+++ b/core/src/ch/asynk/gdx/boardgame/Path.java
@@ -0,0 +1,85 @@
+package ch.asynk.gdx.boardgame;
+
+import java.util.Iterator;
+
+import com.badlogic.gdx.math.Vector3;
+import com.badlogic.gdx.utils.Pool;
+import com.badlogic.gdx.utils.Disposable;
+
+import ch.asynk.gdx.boardgame.pieces.Piece;
+import ch.asynk.gdx.boardgame.utils.IterableArray;
+
+public class Path extends IterableArray<Tile> implements Disposable, Pool.Poolable
+{
+ public static int defaultCapacity = 8;
+
+ private static final Pool<Path> pathPool = new Pool<Path>()
+ {
+ @Override protected Path newObject()
+ {
+ return new Path();
+ }
+ };
+
+ public static Path obtain()
+ {
+ return pathPool.obtain();
+ }
+
+ private Orientation finalOrientation;
+
+ private Path()
+ {
+ super(defaultCapacity);
+ }
+
+ public void setFinalOrientation(Orientation orientation)
+ {
+ this.finalOrientation = orientation;
+ }
+
+ @Override public void reset()
+ {
+ clear();
+ this.finalOrientation = null;
+ }
+
+ @Override public void dispose()
+ {
+ clear();
+ pathPool.free(this);
+ }
+
+ @Override public String toString()
+ {
+ String s = String.format(" o:%s\n", finalOrientation);
+ for (Tile t : this)
+ s += String.format(" %s\n", t.toString());
+ return s;
+ }
+
+ public boolean nextVector(Piece piece, Vector3 v)
+ {
+ if (hasNext()) {
+ Tile cur = current();
+ if (piece.isOn(cur)) {
+ // rotation ...
+ next();
+ Orientation o = (hasNext() ? Orientation.fromTiles(cur, current()) : finalOrientation);
+ // if already facing, transform into a move
+ if (piece.isFacing(o)) {
+ cur = current();
+ if (cur == null) {
+ return true;
+ }
+ }
+ piece.getPosOn(cur, o, v);
+ } else {
+ // regular move, no rotation
+ piece.getPosOn(cur, Orientation.fromR(v.z), v);
+ }
+ return false;
+ }
+ return true;
+ }
+}