summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/gdx/boardgame/Path.java
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-10-17 16:03:07 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2018-10-17 16:03:07 +0200
commitcf85904469c49e881e5a853a1f4d6668c180513d (patch)
treebb0d32c45afc54a675488b590de049d4e423b7e5 /core/src/ch/asynk/gdx/boardgame/Path.java
parenta74a9fd597b623a343f23f0384c0edd32bf61603 (diff)
downloadgdx-boardgame-cf85904469c49e881e5a853a1f4d6668c180513d.zip
gdx-boardgame-cf85904469c49e881e5a853a1f4d6668c180513d.tar.gz
add Path
Diffstat (limited to 'core/src/ch/asynk/gdx/boardgame/Path.java')
-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;
+ }
+}