From cf85904469c49e881e5a853a1f4d6668c180513d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 17 Oct 2018 16:03:07 +0200 Subject: add Path --- core/src/ch/asynk/gdx/boardgame/Path.java | 85 +++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 core/src/ch/asynk/gdx/boardgame/Path.java 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 implements Disposable, Pool.Poolable +{ + public static int defaultCapacity = 8; + + private static final Pool pathPool = new Pool() + { + @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; + } +} -- cgit v1.1-2-g2b99