summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/engine
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk/tankontank/engine')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java19
-rw-r--r--core/src/ch/asynk/tankontank/engine/Tile.java12
2 files changed, 18 insertions, 13 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index 4a4aa3e..0166840 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -26,6 +26,11 @@ import ch.asynk.tankontank.engine.gfx.animations.RunnableAnimation;
public abstract class Board extends Image implements Disposable
{
+ public interface TileBuilder
+ {
+ public Tile getNewTile(float cx, float cy);
+ }
+
public enum Orientation
{
ALL(0, 63),
@@ -146,23 +151,25 @@ public abstract class Board extends Image implements Disposable
protected final List<GridPoint2> areaPoints = new Vector<GridPoint2>(10);
- public Board(Config cfg, Texture texture, Tile tileBuilder)
+ public Board(TileBuilder tileBuilder, Config cfg, Texture texture)
{
super(texture);
this.cfg = cfg;
this.tiles = new Tile[cfg.cols * cfg.rows];
searchBoard = new SearchBoard(this, cfg.cols, cfg.rows);
- boolean evenRow = true;
int idx = 0;
+ boolean evenRow = true;
+ float y = cfg.y0 - cfg.dh + cfg.s;
for (int i = 0; i < cfg.rows; i++) {
- float y = cfg.y0 + (i * cfg.h) - cfg.dh;
+ float x = cfg.x0 + cfg.dw;
+ if (!evenRow) x += cfg.dw;
for ( int j = 0; j < cfg.cols; j ++) {
- float x = cfg.x0 + (j * cfg.w);
- if (!evenRow) x += cfg.dw;
- this.tiles[idx] = tileBuilder.getNewAt(x, y);
+ this.tiles[idx] = tileBuilder.getNewTile(x, y);
idx += 1;
+ x += cfg.w;
}
+ y += cfg.h;
evenRow = !evenRow;
}
}
diff --git a/core/src/ch/asynk/tankontank/engine/Tile.java b/core/src/ch/asynk/tankontank/engine/Tile.java
index 24176f3..835f464 100644
--- a/core/src/ch/asynk/tankontank/engine/Tile.java
+++ b/core/src/ch/asynk/tankontank/engine/Tile.java
@@ -6,6 +6,7 @@ import java.util.ArrayDeque;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
+import com.badlogic.gdx.math.Vector2;
import ch.asynk.tankontank.engine.gfx.Drawable;
import ch.asynk.tankontank.engine.gfx.StackedImages;
@@ -14,17 +15,19 @@ public abstract class Tile implements Drawable
{
private StackedImages overlays;
protected ArrayDeque<Pawn> stack;
+ private Vector2 center;
- public abstract Tile getNewAt(float x, float y);
public abstract boolean atLeastOneMove(Pawn pawn);
public abstract boolean road(Board.Orientation side);
public abstract int costFrom(Pawn pawn, Board.Orientation side, boolean road);
public abstract boolean hasTargetsFor(Pawn pawn);
- public Tile(TextureAtlas atlas)
+ public Tile(float x, float y, TextureAtlas atlas)
{
this.stack = null;
+ this.center = new Vector2(x, y);
this.overlays = new StackedImages(atlas);
+ this.overlays.centerOn(x, y);
}
public int push(Pawn pawn)
@@ -76,11 +79,6 @@ public abstract class Tile implements Drawable
return mustBeDrawn();
}
- public void setPosition(float x, float y, float z)
- {
- overlays.setPosition(x, y, z);
- }
-
@Override
public void draw(Batch batch)
{