summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-23 20:41:23 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-23 20:41:23 +0200
commit37b44d0bbd370e3b71792759c43138e476cb871b (patch)
treea88b4f58672fb6b09d68b7a57f52b45d84e0b84d
parent7d697e2d13efebdaa569b22e3f668924aef2701d (diff)
downloadRustAndDust-37b44d0bbd370e3b71792759c43138e476cb871b.zip
RustAndDust-37b44d0bbd370e3b71792759c43138e476cb871b.tar.gz
add Hex.OFFMAP
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java29
-rw-r--r--core/src/ch/asynk/tankontank/game/Hex.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/MapA.java5
4 files changed, 26 insertions, 12 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index f5527e7..ca7230c 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -58,7 +58,7 @@ public abstract class Board extends Image implements Disposable
}
protected Config cfg;
- protected Tile[][] board;
+ private Tile[] board;
boolean transform;
private Matrix4 prevTransform;
@@ -76,22 +76,27 @@ public abstract class Board extends Image implements Disposable
{
super(texture);
this.cfg = cfg;
+ this.board = new Tile[cfg.rows * cfg.cols];
- this.board = new Tile[cfg.rows][];
boolean evenRow = true;
+ int idx = 0;
for (int i = 0; i < cfg.rows; i++) {
float y = cfg.y0 + (i * cfg.h) - cfg.dh;
- int c = (evenRow ? cfg.cols : cfg.cols - 1);
- this.board[i] = new Tile[c];
- for ( int j = 0; j < c; j ++) {
+ for ( int j = 0; j < cfg.cols; j ++) {
float x = cfg.x0 + (j * cfg.w);
if (!evenRow) x += cfg.dw;
- this.board[i][j] = tileBuilder.getNewAt(x, y);
+ this.board[idx] = tileBuilder.getNewAt(x, y);
+ idx += 1;
}
evenRow = !evenRow;
}
}
+ public Tile getTile(int col, int row)
+ {
+ return board[col + (row * cfg.cols)];
+ }
+
@Override
public void setPosition(float x, float y)
{
@@ -196,7 +201,7 @@ public abstract class Board extends Image implements Disposable
public void clearOverlaysOn(int col, int row)
{
- clearOverlaysOn(board[row][col]);
+ clearOverlaysOn(getTile(col, row));
}
public void clearOverlaysOn(Tile tile)
@@ -209,7 +214,7 @@ public abstract class Board extends Image implements Disposable
public void enableOverlayOn(int col, int row, int i, boolean enable)
{
- enableOverlayOn(board[row][col], i, enable);
+ enableOverlayOn(getTile(col, row), i, enable);
}
public void enableOverlayOn(Tile tile, int i, boolean enable)
@@ -240,19 +245,19 @@ public abstract class Board extends Image implements Disposable
private Pawn getTopPawnAt(int col, int row)
{
- return board[row][col].getTopPawn();
+ return getTile(col, row).getTopPawn();
}
private int pushPawnAt(Pawn pawn, int col, int row)
{
- Tile tile = board[row][col];
+ Tile tile = getTile(col, row);
tilesToDraw.add(tile);
return tile.push(pawn);
}
private int removePawnFrom(Pawn pawn, int col, int row)
{
- Tile tile = board[row][col];
+ Tile tile = getTile(col, row);
int n = tile.remove(pawn);
if (!tile.mustBeDrawn())
tilesToDraw.remove(tile);
@@ -261,6 +266,7 @@ public abstract class Board extends Image implements Disposable
public Vector2 getHexCenterAt(GridPoint2 tile)
{
+ // FIXME could ask it to the Tile
float x = cfg.x0 + ((tile.x * cfg.w) + (cfg.w / 2));
float y = cfg.y0 + ((tile.y * cfg.h) + (cfg.s / 2));
if ((tile.y % 2) == 1) x += cfg.dw;
@@ -274,6 +280,7 @@ public abstract class Board extends Image implements Disposable
private Vector2 getPawnPosAt(Pawn pawn, int col, int row)
{
+ // FIXME could ask it to the Tile
float x = cfg.x0 + ((col * cfg.w) + ((cfg.w - pawn.getHeight()) / 2));
float y = cfg.y0 + ((row * cfg.h) + ((cfg.s - pawn.getWidth()) / 2));
if ((row % 2) == 1) x += cfg.dw;
diff --git a/core/src/ch/asynk/tankontank/game/Hex.java b/core/src/ch/asynk/tankontank/game/Hex.java
index a68aa75..404f763 100644
--- a/core/src/ch/asynk/tankontank/game/Hex.java
+++ b/core/src/ch/asynk/tankontank/game/Hex.java
@@ -9,6 +9,8 @@ public class Hex extends Tile
{
public enum Terrain
{
+ OFFMAP,
+ BLOCKED,
CLEAR,
HILLS,
WOODS,
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index bb41af3..c15dce5 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -26,7 +26,7 @@ public abstract class Map extends Board
protected Hex getHex(int col, int row)
{
- return (Hex) board[row][col];
+ return (Hex) getTile(col, row);
}
public boolean drag(float dx, float dy)
diff --git a/core/src/ch/asynk/tankontank/game/MapA.java b/core/src/ch/asynk/tankontank/game/MapA.java
index bef711d..54a1dfb 100644
--- a/core/src/ch/asynk/tankontank/game/MapA.java
+++ b/core/src/ch/asynk/tankontank/game/MapA.java
@@ -35,6 +35,11 @@ public class MapA extends Map
getHex(1, 6).terrain = Hex.Terrain.TOWN;
getHex(3, 7).terrain = Hex.Terrain.TOWN;
+ getHex(9, 1).terrain = Hex.Terrain.OFFMAP;
+ getHex(9, 3).terrain = Hex.Terrain.OFFMAP;
+ getHex(9, 5).terrain = Hex.Terrain.OFFMAP;
+ getHex(9, 7).terrain = Hex.Terrain.OFFMAP;
+
int N = Map.Orientation.NORTH.s;
int S = Map.Orientation.SOUTH.s;
int NE = Map.Orientation.NORTH_EAST.s;