summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-03 11:45:16 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-03 11:45:16 +0200
commit59d71e6080a82aeeba1f07f86fd4d3f42dfa8e9d (patch)
treed8760b0323f7a8a7937bd06f99d1a05f405bf559 /core/src/ch/asynk/tankontank
parentcb68989e0ea376d19f05dfa77c3d72a094102f9c (diff)
downloadRustAndDust-59d71e6080a82aeeba1f07f86fd4d3f42dfa8e9d.zip
RustAndDust-59d71e6080a82aeeba1f07f86fd4d3f42dfa8e9d.tar.gz
Board: getFinalPath(...) returns an array of Vector3, add movePawn(...)
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java66
1 files 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<GridPoint3> gridPoint3Pool = new Pool<GridPoint3>() {
+ private final Pool<Vector3> vector3Pool = new Pool<Vector3>() {
@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<GridPoint3> path)
+ public int getFinalPath(Pawn pawn, Vector<Vector3> path, Orientation finalOrientation)
{
List<Vector<SearchBoard.Node>> 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<SearchBoard.Node> 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<Vector3> 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()));