From 429be1b305dbef415387e9e6a5e56ad8e49fd4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 18 Oct 2018 11:01:43 +0200 Subject: Path : add private Tile from and to --- core/src/ch/asynk/gdx/boardgame/Path.java | 35 ++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/core/src/ch/asynk/gdx/boardgame/Path.java b/core/src/ch/asynk/gdx/boardgame/Path.java index 5bc46c3..de148ae 100644 --- a/core/src/ch/asynk/gdx/boardgame/Path.java +++ b/core/src/ch/asynk/gdx/boardgame/Path.java @@ -27,6 +27,8 @@ public class Path extends IterableArray implements Disposable, Pool.Poolab } private Orientation finalOrientation; + private Tile from; + private Tile to; private Path() { @@ -41,6 +43,8 @@ public class Path extends IterableArray implements Disposable, Pool.Poolab @Override public void reset() { clear(); + this.from = null; + this.to = null; this.finalOrientation = null; } @@ -58,25 +62,36 @@ public class Path extends IterableArray implements Disposable, Pool.Poolab return s; } - public boolean nextVector(Piece piece, Vector3 v) + public Tile from() + { + return from; + } + + public Tile to() + { + return to; + } + + public boolean nextPosition(Piece piece, Vector3 v) { if (hasNext()) { - Tile cur = current(); - if (piece.isOn(cur)) { + to = current(); + if (piece.isOn(to)) { // rotation ... + from = to; next(); - Orientation o = (hasNext() ? Orientation.fromTiles(cur, current()) : finalOrientation); - // if already facing, transform into a move + Orientation o = (hasNext() ? Orientation.fromTiles(from, current()) : finalOrientation); + // if already facing, transform into a straight move if (piece.isFacing(o)) { - cur = current(); - if (cur == null) { + to = current(); + if (to == null) { return true; } } - piece.getPosOn(cur, o, v); + piece.getPosOn(to, o, v); } else { - // regular move, no rotation - piece.getPosOn(cur, Orientation.fromR(v.z), v); + // rotation finished, regular move + piece.getPosOn(to, Orientation.fromR(v.z), v); } return false; } -- cgit v1.1-2-g2b99