summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java9
-rw-r--r--core/src/ch/asynk/tankontank/engine/Pawn.java10
-rw-r--r--core/src/ch/asynk/tankontank/engine/Tile.java22
-rw-r--r--core/src/ch/asynk/tankontank/game/Hex.java6
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/battles/Factory.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateCommon.java2
7 files changed, 31 insertions, 24 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index 94cb083..07c3c8b 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -32,7 +32,7 @@ public abstract class Board implements Disposable
public interface TileBuilder
{
- public Tile getNewTile(float cx, float cy);
+ public Tile getNewTile(float x, float y, int col, int row);
}
public static class Config
@@ -115,7 +115,7 @@ public abstract class Board implements Disposable
float x = cfg.x0 + cfg.dw;
if (!evenRow) x += cfg.dw;
for ( int j = 0; j < cfg.cols; j ++) {
- this.tiles[idx] = tileBuilder.getNewTile(x, y);
+ this.tiles[idx] = tileBuilder.getNewTile(x, y, (j + ((i + 1) / 2)), i);
idx += 1;
x += cfg.w;
}
@@ -545,8 +545,9 @@ public abstract class Board implements Disposable
protected Vector2 getPawnPosAt(Pawn pawn, GridPoint2 coords, Vector2 pos)
{
- Vector2 center = getTile(coords).getCenter();
- return pawn.getPosAt(center, pos);
+ // FIXME the pawn should return its Vector3
+ Tile tile = getTile(coords);
+ return pawn.getPosAt(tile.getX(), tile.getY(), pos);
}
public Pawn setPawnAt(Pawn pawn, GridPoint2 coords, Orientation o)
diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java
index c21a088..bde5f0c 100644
--- a/core/src/ch/asynk/tankontank/engine/Pawn.java
+++ b/core/src/ch/asynk/tankontank/engine/Pawn.java
@@ -131,14 +131,14 @@ public abstract class Pawn implements Moveable, Disposable
return new Vector2(x, y);
}
- public Vector2 getPosAt(Vector2 center, Vector2 pos)
+ public Vector2 getPosAt(float x, float y, Vector2 pos)
{
- float x = (center.x - (image.getWidth() / 2f));
- float y = (center.y - (image.getHeight() / 2f));
+ float cx = (x - (image.getWidth() / 2f));
+ float cy = (y - (image.getHeight() / 2f));
if (pos == null)
- return new Vector2(x, y);
+ return new Vector2(cx, cy);
else
- pos.set(x, y);
+ pos.set(cx, cy);
return pos;
}
diff --git a/core/src/ch/asynk/tankontank/engine/Tile.java b/core/src/ch/asynk/tankontank/engine/Tile.java
index 88edd4f..f1e2c12 100644
--- a/core/src/ch/asynk/tankontank/engine/Tile.java
+++ b/core/src/ch/asynk/tankontank/engine/Tile.java
@@ -16,7 +16,10 @@ import ch.asynk.tankontank.engine.gfx.StackedImages;
public abstract class Tile implements Drawable, Disposable
{
- private Vector2 center;
+ protected int col;
+ protected int row;
+ protected float x;
+ protected float y;
private StackedImages overlays;
private ArrayDeque<Pawn> stack;
@@ -32,14 +35,22 @@ public abstract class Tile implements Drawable, Disposable
{
}
- public Tile(float x, float y, TextureAtlas atlas)
+ public Tile(float x, float y, int col, int row, TextureAtlas atlas)
{
this.stack = null;
- this.center = new Vector2(x, y);
+ this.x = x;
+ this.y = y;
+ this.col = col;
+ this.row = row;
this.overlays = new StackedImages(atlas);
this.overlays.centerOn(x, y);
}
+ public float getX() { return x; }
+ public float getY() { return y; }
+ public int getCol() { return col; }
+ public int getRow() { return row; }
+
@Override
public void dispose()
{
@@ -47,11 +58,6 @@ public abstract class Tile implements Drawable, Disposable
overlays.dispose();
}
- public Vector2 getCenter()
- {
- return center;
- }
-
public boolean isEmpty()
{
if (stack == null) return true;
diff --git a/core/src/ch/asynk/tankontank/game/Hex.java b/core/src/ch/asynk/tankontank/game/Hex.java
index 84b2a34..e5a61d4 100644
--- a/core/src/ch/asynk/tankontank/game/Hex.java
+++ b/core/src/ch/asynk/tankontank/game/Hex.java
@@ -35,12 +35,12 @@ public class Hex extends Tile
public String toString()
{
- return "[" + getCenter().x + ";" + getCenter().y + "] " + "t:" + terrain + " r:" + roads;
+ return "(" + col + ";" + row + ") [" + x + ";" + y + "] " + "t:" + terrain + " r:" + roads;
}
- public Hex(float x, float y, TextureAtlas atlas)
+ public Hex(float x, float y, int col, int row, TextureAtlas atlas)
{
- super(x, y, atlas);
+ super(x, y, col, row, atlas);
this.terrain = Terrain.CLEAR;
this.roads = 0;
}
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index c0b799d..68c3b12 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -92,7 +92,7 @@ public abstract class Map extends Board
return (Hex) getTile(col, row);
}
- protected Hex getHexSafe(GridPoint2 hex)
+ public Hex getHexSafe(GridPoint2 hex)
{
return (Hex) getTileSafe(hex.x, hex.y);
}
diff --git a/core/src/ch/asynk/tankontank/game/battles/Factory.java b/core/src/ch/asynk/tankontank/game/battles/Factory.java
index f753d47..8ab3ba8 100644
--- a/core/src/ch/asynk/tankontank/game/battles/Factory.java
+++ b/core/src/ch/asynk/tankontank/game/battles/Factory.java
@@ -149,8 +149,8 @@ public class Factory implements Board.TileBuilder, Disposable
return u;
}
- public Hex getNewTile(float cx, float cy)
+ public Hex getNewTile(float x, float y, int col, int row)
{
- return new Hex(cx, cy, atlas);
+ return new Hex(x, y, col, row, atlas);
}
}
diff --git a/core/src/ch/asynk/tankontank/game/states/StateCommon.java b/core/src/ch/asynk/tankontank/game/states/StateCommon.java
index e729a84..2edda2c 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateCommon.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateCommon.java
@@ -113,7 +113,7 @@ public abstract class StateCommon implements State
isEnemy = ctrl.player.isEnemy(selectedPawn);
else
isEnemy = false;
- System.err.println(" select (" + selectedHex.x + ";" + selectedHex.y + ") " + selectedPawn + (isEnemy ? " enemy " : " friend "));
+ System.err.println(" select " + map.getHexSafe(selectedHex) + selectedPawn + (isEnemy ? " enemy " : " friend "));
}
protected void showPossibleTargetsMovesAssists(Pawn pawn)