summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-07 15:50:43 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-07 15:50:43 +0200
commit54404666eced21a4b997823bcb76eb203b155bad (patch)
treed2f688a9048bbed9eff9c60f36104f14c5658164 /core/src/ch
parentc1cf9a6c797c91b1a88abd20577218e44df43fc9 (diff)
downloadRustAndDust-54404666eced21a4b997823bcb76eb203b155bad.zip
RustAndDust-54404666eced21a4b997823bcb76eb203b155bad.tar.gz
Board: add getTileSafe() and getAdjacentTiles()
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index b906348..0ef2a6e 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -132,6 +132,25 @@ public abstract class Board implements Disposable
return tiles[idx];
}
+ public Tile getTileSafe(int col, int row)
+ {
+ int colOffset = ((row + 1) / 2);
+ if ((col < colOffset) || (row < 0) || (row >= cfg.rows) || ((col - colOffset) >= cfg.cols))
+ return null;
+
+ return tiles[((col - colOffset)) + (row * cfg.cols)];
+ }
+
+ public void getAdjacentTiles(GridPoint2 hex, Tile tiles[])
+ {
+ tiles[0] = getTileSafe((hex.x - 1), hex.y);
+ tiles[1] = getTileSafe(hex.x, (hex.y + 1));
+ tiles[2] = getTileSafe((hex.x + 1), (hex.y + 1));
+ tiles[3] = getTileSafe((hex.x + 1), hex.y);
+ tiles[4] = getTileSafe(hex.x, (hex.y - 1));
+ tiles[5] = getTileSafe((hex.x - 1), (hex.y - 1));
+ }
+
public float getWidth()
{
return image.getWidth();