summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-22 12:09:40 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-22 12:09:40 +0200
commitc3d3d2132324fed57e7d6ab6ec11eb588216fae7 (patch)
tree306214defc7fccdc92507a5eec37083efe4a9c94 /core/src/ch/asynk
parent6f0054a030b5c38346940d871343b3238bb5eb1e (diff)
downloadRustAndDust-c3d3d2132324fed57e7d6ab6ec11eb588216fae7.zip
RustAndDust-c3d3d2132324fed57e7d6ab6ec11eb588216fae7.tar.gz
Board: neigbours is no more GridPoint2[] but Tile[]
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java35
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java4
2 files changed, 13 insertions, 26 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index b33fad4..93274eb 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -27,7 +27,7 @@ import ch.asynk.tankontank.engine.gfx.animations.RunnableAnimation;
public abstract class Board implements Disposable
{
- private final GridPoint2 neighbours[] = new GridPoint2[6];
+ private final Tile neighbours[] = new Tile[6];
protected List<ArrayList<SearchBoard.Node>> paths;
public interface TileBuilder
@@ -81,8 +81,6 @@ public abstract class Board implements Disposable
protected Board(int cols, int rows)
{
- for (int i = 0; i < 6; i++)
- neighbours[i] = new GridPoint2(-1, -1);
searchBoard = new SearchBoard(this, cols, rows);
}
@@ -107,9 +105,6 @@ public abstract class Board implements Disposable
y += cfg.h;
evenRow = !evenRow;
}
-
- for (int i = 0; i < 6; i++)
- neighbours[i] = new GridPoint2(-1, -1);
}
@Override
@@ -177,24 +172,14 @@ public abstract class Board implements Disposable
private void getAdjacentTiles(GridPoint2 coords, Tile tiles[])
{
- tiles[0] = getTileSafe((coords.x - 1), coords.y);
- tiles[1] = getTileSafe(coords.x, (coords.y + 1));
+ tiles[0] = getTileSafe((coords.x - 1), (coords.y));
+ tiles[1] = getTileSafe((coords.x), (coords.y + 1));
tiles[2] = getTileSafe((coords.x + 1), (coords.y + 1));
- tiles[3] = getTileSafe((coords.x + 1), coords.y);
- tiles[4] = getTileSafe(coords.x, (coords.y - 1));
+ tiles[3] = getTileSafe((coords.x + 1), (coords.y));
+ tiles[4] = getTileSafe((coords.x), (coords.y - 1));
tiles[5] = getTileSafe((coords.x - 1), (coords.y - 1));
}
- private void buildNeighboursFor(GridPoint2 coords)
- {
- neighbours[0].set((coords.x - 1), coords.y);
- neighbours[1].set(coords.x, (coords.y + 1));
- neighbours[2].set((coords.x + 1), (coords.y + 1));
- neighbours[3].set((coords.x + 1), coords.y);
- neighbours[4].set(coords.x, (coords.y - 1));
- neighbours[5].set((coords.x - 1), (coords.y - 1));
- }
-
public void addAnimation(Animation a)
{
nextAnimations.add(a);
@@ -343,14 +328,16 @@ public abstract class Board implements Disposable
protected int buildMoveAssists(Pawn pawn, GridPoint2 coords, List<GridPoint2> assists)
{
assists.clear();
- buildNeighboursFor(coords);
+ getAdjacentTiles(coords, neighbours);
for (int i = 0; i < 6; i++) {
- GridPoint2 neighbour = neighbours[i];
- Tile t = getTileSafe(neighbour);
+ Tile t = neighbours[i];
if (t != null) {
+ // FIXME should support may pawns per tile
Pawn p = t.getTopPawn();
if ((p != null) && p.canMove() && !pawn.isEnemy(p)) {
- assists.add(neighbour);
+ GridPoint2 assist = gridPoint2Pool.obtain();
+ assist.set(t.getCol(), t.getRow());
+ assists.add(assist);
}
}
}
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index 68c3b12..9c7a882 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -57,7 +57,7 @@ public abstract class Map extends Board
public void clearAll()
{
- moveAssists.clear();
+ clearPointVector(moveAssists);;
clearPointVector(attackAssists);
activablePawns.clear();
activatedPawns.clear();
@@ -241,7 +241,7 @@ public abstract class Map extends Board
public int buildMoveAssists(Pawn pawn, GridPoint2 hex)
{
if (!pawn.isHq()) {
- moveAssists.clear();
+ clearPointVector(moveAssists);
return 0;
}
return buildMoveAssists(pawn, hex, moveAssists);