From 59d71e6080a82aeeba1f07f86fd4d3f42dfa8e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 3 Oct 2014 11:45:16 +0200 Subject: Board: getFinalPath(...) returns an array of Vector3, add movePawn(...) --- core/src/ch/asynk/tankontank/engine/Board.java | 66 ++++++++++++++++++++------ 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index f5cfca9..cdc8504 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -18,7 +18,6 @@ import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.GridPoint2; -import com.badlogic.gdx.math.GridPoint3; import com.badlogic.gdx.math.Matrix4; import ch.asynk.tankontank.engine.gfx.Image; @@ -54,10 +53,10 @@ public abstract class Board implements Disposable } }; - private final Pool gridPoint3Pool = new Pool() { + private final Pool vector3Pool = new Pool() { @Override - protected GridPoint3 newObject() { - return new GridPoint3(); + protected Vector3 newObject() { + return new Vector3(); } }; @@ -325,28 +324,51 @@ public abstract class Board implements Disposable return nodesToSet(paths, points); } - public int getFinalPath(Vector path) + public int getFinalPath(Pawn pawn, Vector path, Orientation finalOrientation) { List> paths = searchBoard.possiblePaths(); - for (GridPoint3 v : path) - gridPoint3Pool.free(v); + for (Vector3 v : path) + vector3Pool.free(v); path.clear(); if (paths.size() != 1) return 0; + Vector2 pawnPos = new Vector2(); + SearchBoard.Node prevNode = null; + Vector3 prevVector = null; + Orientation o = Orientation.KEEP; + GridPoint2 coords = gridPoint2Pool.obtain(); + Vector nodes = paths.get(0); - SearchBoard.Node prev = nodes.get(nodes.size() - 1); - for (int i = (nodes.size() - 2); i >= 0; i--) { + + for (int i = (nodes.size() - 1); i >= 0; i--) { SearchBoard.Node node = nodes.get(i); - GridPoint3 point = gridPoint3Pool.obtain(); - Orientation o = Orientation.fromMove(prev.col, prev.row, node.col, node.row); - point.set(node.col, node.row, (int) o.r()); - path.add(point); - prev = node; + System.out.println(node.col+" "+node.row); + + 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); + coords.set(node.col, node.row); + getPawnPosAt(pawn, coords, pawnPos); + prevVector = vector3Pool.obtain(); + prevVector.set(pawnPos.x, pawnPos.y, 0f); + } + + prevNode = node; } + prevVector.z = finalOrientation.r(); + path.add(prevVector); + + gridPoint2Pool.free(coords); + return path.size(); } @@ -450,6 +472,22 @@ public abstract class Board implements Disposable pawn.pushMove(pos.x, pos.y, o); } + public void movePawn(final Pawn pawn, Vector path) + { + removePawnFrom(pawn, getHexAt(pawn.getLastPosition())); + + final Vector3 finalPos = path.get(path.size() - 1); + + AnimationSequence seq = pawn.getMoveAnimation(path); + seq.addAnimation(RunnableAnimation.get(pawn, new Runnable() { + @Override + public void run() { + pushPawnAt(pawn, new GridPoint2(getHexAt(finalPos))); + } + })); + addPawnAnimation(pawn, seq); + } + public void resetPawnMoves(final Pawn pawn) { removePawnFrom(pawn, getHexAt(pawn.getLastPosition())); -- cgit v1.1-2-g2b99