summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-27 22:59:28 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-27 22:59:28 +0200
commitcea2deb7e2106f9d53f08a80b8cf3c66ed80d0b3 (patch)
tree799c1146b0344c94ce9d36ed2506fb2b9d1cd5d3
parent296f56aab97d8cf38aa04ec4d7af18b8330369a1 (diff)
downloadRustAndDust-cea2deb7e2106f9d53f08a80b8cf3c66ed80d0b3.zip
RustAndDust-cea2deb7e2106f9d53f08a80b8cf3c66ed80d0b3.tar.gz
Tiles have a center, GameFactory implements Board.TileBuilder to create Hex(cx,cy)
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java19
-rw-r--r--core/src/ch/asynk/tankontank/engine/Tile.java12
-rw-r--r--core/src/ch/asynk/tankontank/game/GameFactory.java10
-rw-r--r--core/src/ch/asynk/tankontank/game/Hex.java15
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/MapA.java4
6 files changed, 31 insertions, 33 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)
{
diff --git a/core/src/ch/asynk/tankontank/game/GameFactory.java b/core/src/ch/asynk/tankontank/game/GameFactory.java
index 5ccb419..6558fc4 100644
--- a/core/src/ch/asynk/tankontank/game/GameFactory.java
+++ b/core/src/ch/asynk/tankontank/game/GameFactory.java
@@ -8,7 +8,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
import ch.asynk.tankontank.engine.Board;
-public class GameFactory implements Disposable
+public class GameFactory implements Board.TileBuilder, Disposable
{
private TextureAtlas usAtlas;
private TextureAtlas geAtlas;
@@ -136,8 +136,7 @@ public class GameFactory implements Disposable
Map m = null;
switch(t) {
case MAP_A:
- m = new MapA(config(), manager.get("images/map_a.png", Texture.class), hexAtlas);
- // m = new Map(config(), manager.get("images/map_a.png", Texture.class), hexAtlas);
+ m = new MapA(this, config(), manager.get("images/map_a.png", Texture.class));
break;
case MAP_B:
// m = new Map(config(), manager.get("images/map_b.png", Texture.class), hexAtlas);
@@ -146,4 +145,9 @@ public class GameFactory implements Disposable
return m;
}
+
+ public Hex getNewTile(float cx, float cy)
+ {
+ return new Hex(cx, cy, hexAtlas);
+ }
}
diff --git a/core/src/ch/asynk/tankontank/game/Hex.java b/core/src/ch/asynk/tankontank/game/Hex.java
index c8c7361..2d36960 100644
--- a/core/src/ch/asynk/tankontank/game/Hex.java
+++ b/core/src/ch/asynk/tankontank/game/Hex.java
@@ -25,25 +25,14 @@ public class Hex extends Tile
public static final int GREEN = 2;
public static final int BLUE = 0;
- public static TextureAtlas atlas = null;
-
public Terrain terrain;
public int roads;
- @Override
- public Hex getNewAt(float x, float y)
- {
- Hex hex = new Hex(atlas);
- hex.setPosition(x, y, 0);
- return hex;
- }
-
- public Hex(TextureAtlas atlas)
+ public Hex(float x, float y, TextureAtlas atlas)
{
- super(atlas);
+ super(x, y, atlas);
this.terrain = Terrain.CLEAR;
this.roads = 0;
- Hex.atlas = atlas;
}
@Override
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index a374e7e..afa6778 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -18,9 +18,9 @@ public abstract class Map extends Board
protected abstract void setup();
- public Map(Board.Config cfg, Texture texture, TextureAtlas hexAtlas)
+ public Map(GameFactory gameFactory, Board.Config cfg, Texture texture)
{
- super(cfg, texture, new Hex(hexAtlas));
+ super(gameFactory, cfg, texture);
setup();
}
diff --git a/core/src/ch/asynk/tankontank/game/MapA.java b/core/src/ch/asynk/tankontank/game/MapA.java
index 54a1dfb..dbfd58a 100644
--- a/core/src/ch/asynk/tankontank/game/MapA.java
+++ b/core/src/ch/asynk/tankontank/game/MapA.java
@@ -7,9 +7,9 @@ import ch.asynk.tankontank.engine.Board;
public class MapA extends Map
{
- public MapA(Board.Config cfg, Texture texture, TextureAtlas hexAtlas)
+ public MapA(GameFactory gameFactory, Board.Config cfg, Texture texture)
{
- super(cfg, texture, hexAtlas);
+ super(gameFactory, cfg, texture);
}
@Override