diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-03 18:01:26 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-03 18:01:26 +0200 |
commit | f7170469e6ff105912c2c63aa09598642acb0f31 (patch) | |
tree | 101ae0ec68ca65aedea2d9a56742538cb5137ece /core | |
parent | 815686901083acc1d416bcdc3c82296761875136 (diff) | |
download | RustAndDust-f7170469e6ff105912c2c63aa09598642acb0f31.zip RustAndDust-f7170469e6ff105912c2c63aa09598642acb0f31.tar.gz |
Board: fix path, rotate on place then move
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 7ebece7..d4d1021 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -335,10 +335,15 @@ public abstract class Board implements Disposable if (paths.size() != 1) return 0; - Vector2 pawnPos = new Vector2(); + SearchBoard.Node prevNode = null; - Vector3 prevVector = null; - Orientation o = Orientation.KEEP; + + Vector3 v = pawn.getLastPosition(); + Vector3 prevVector = vector3Pool.obtain(); + prevVector.set(v.x, v.y, v.z); + Orientation prevOrientation = pawn.getOrientation(); + + Vector2 pawnPos = new Vector2(); GridPoint2 coords = gridPoint2Pool.obtain(); Vector<SearchBoard.Node> nodes = paths.get(0); @@ -346,16 +351,18 @@ public abstract class Board implements Disposable for (int i = (nodes.size() - 1); i >= 0; i--) { SearchBoard.Node node = nodes.get(i); - if (prevVector == null) { - Vector3 p = pawn.getLastPosition(); - prevVector = vector3Pool.obtain(); - prevVector.set(p.x, p.y, 0f); - } else { - o = Orientation.fromMove(prevNode.col, prevNode.row, node.col, node.row); - prevVector.z = o.r(); - path.add(prevVector); + if (prevNode != null) { + Orientation o = Orientation.fromMove(prevNode.col, prevNode.row, node.col, node.row); + if (o != prevOrientation) { + prevVector.z = o.r(); + path.add(prevVector); + prevVector = vector3Pool.obtain(); + } coords.set(node.col, node.row); getPawnPosAt(pawn, coords, pawnPos); + prevVector.set(pawnPos.x, pawnPos.y, o.r()); + path.add(prevVector); + prevOrientation = o; prevVector = vector3Pool.obtain(); prevVector.set(pawnPos.x, pawnPos.y, 0f); } @@ -363,8 +370,12 @@ public abstract class Board implements Disposable prevNode = node; } - prevVector.z = finalOrientation.r(); - path.add(prevVector); + if (finalOrientation != prevOrientation) { + prevVector.z = finalOrientation.r(); + path.add(prevVector); + } else { + vector3Pool.free(prevVector); + } gridPoint2Pool.free(coords); |