summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-21 10:06:53 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-21 10:06:53 +0200
commitf7264e865d49673df59c6f8f08e323db41f8894b (patch)
tree7312915c4d916c7b572e98b849c378cb0ecee040
parent8d43e91dcf005cf076fb3cd571f6125df5837c8d (diff)
downloadRustAndDust-f7264e865d49673df59c6f8f08e323db41f8894b.zip
RustAndDust-f7264e865d49673df59c6f8f08e323db41f8894b.tar.gz
update Map,Hex,Unit extends Board,Tile,Pawn fix GameScreen
-rw-r--r--core/src/ch/asynk/tankontank/game/GameFactory.java18
-rw-r--r--core/src/ch/asynk/tankontank/game/Hex.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java41
-rw-r--r--core/src/ch/asynk/tankontank/game/Unit.java4
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java4
5 files changed, 54 insertions, 17 deletions
diff --git a/core/src/ch/asynk/tankontank/game/GameFactory.java b/core/src/ch/asynk/tankontank/game/GameFactory.java
index f8b05ea..e271f4b 100644
--- a/core/src/ch/asynk/tankontank/game/GameFactory.java
+++ b/core/src/ch/asynk/tankontank/game/GameFactory.java
@@ -5,9 +5,7 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
-import ch.asynk.tankontank.engine.Map;
-import ch.asynk.tankontank.engine.MapNode;
-import ch.asynk.tankontank.engine.Tile;
+import ch.asynk.tankontank.engine.Board;
public class GameFactory
{
@@ -109,9 +107,9 @@ public class GameFactory
MAP_B
}
- private static Map.Config config()
+ private static Board.Config config()
{
- Map.Config cfg = new Map.Config();
+ Board.Config cfg = new Board.Config();
cfg.cols = 11;
cfg.rows = 9;
cfg.x0 = 83;
@@ -128,14 +126,14 @@ public class GameFactory
public static Map getMap(AssetManager manager, MapType t)
{
- Map.Config cfg = config();
+ Board.Config cfg = config();
- Tile[][] board = new Tile[cfg.rows][];
+ Hex[][] board = new Hex[cfg.rows][];
boolean evenRow = true;
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);
- board[i] = new Tile[c];
+ board[i] = new Hex[c];
for ( int j = 0; j < c; j ++) {
float x = cfg.x0 + (j * cfg.w) ;//+ (cfg.w / 2f);
if (!evenRow) x += cfg.dw;
@@ -149,10 +147,10 @@ public class GameFactory
Map m = null;
switch(t) {
case MAP_A:
- m = new MapNode(config(), board, manager.get("images/map_a.png", Texture.class));
+ m = new Map(config(), board, manager.get("images/map_a.png", Texture.class));
break;
case MAP_B:
- m = new MapNode(config(), board, manager.get("images/map_b.png", Texture.class));
+ m = new Map(config(), board, manager.get("images/map_b.png", Texture.class));
break;
}
diff --git a/core/src/ch/asynk/tankontank/game/Hex.java b/core/src/ch/asynk/tankontank/game/Hex.java
index 2d07b52..ae6499e 100644
--- a/core/src/ch/asynk/tankontank/game/Hex.java
+++ b/core/src/ch/asynk/tankontank/game/Hex.java
@@ -2,9 +2,9 @@ package ch.asynk.tankontank.game;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
-import ch.asynk.tankontank.engine.TileOverlays;
+import ch.asynk.tankontank.engine.Tile;
-public class Hex extends TileOverlays
+public class Hex extends Tile
{
public enum Terrain
{
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
new file mode 100644
index 0000000..9eef409
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -0,0 +1,41 @@
+package ch.asynk.tankontank.game;
+
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.math.GridPoint2;
+
+import ch.asynk.tankontank.engine.Board;
+import ch.asynk.tankontank.engine.Pawn;
+
+public class Map extends Board
+{
+ private Pawn currentPawn;
+ private GridPoint2 currentHex = new GridPoint2(-1, -1);
+
+ public Map(Board.Config cfg, Hex[][] board, Texture texture)
+ {
+ super(cfg, board, texture);
+ }
+
+ public boolean drag(float dx, float dy)
+ {
+ if (currentPawn == null) return false;
+ currentPawn.translate(dx, dy);
+ return true;
+ }
+
+ public void touchDown(float x, float y)
+ {
+ getHexAt(currentHex, x, y);
+ if (currentHex.x != -1) {
+ currentPawn = getTopPawnAt(currentHex);
+ }
+ }
+
+ public void touchUp(float x, float y)
+ {
+ getHexAt(currentHex, x, y);
+ if (currentPawn != null) {
+ movePawnTo(currentPawn, currentHex);
+ }
+ }
+}
diff --git a/core/src/ch/asynk/tankontank/game/Unit.java b/core/src/ch/asynk/tankontank/game/Unit.java
index 61833eb..31a822d 100644
--- a/core/src/ch/asynk/tankontank/game/Unit.java
+++ b/core/src/ch/asynk/tankontank/game/Unit.java
@@ -2,9 +2,9 @@ package ch.asynk.tankontank.game;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
-import ch.asynk.tankontank.engine.PawnImage;
+import ch.asynk.tankontank.engine.Pawn;
-public class Unit extends PawnImage
+public class Unit extends Pawn
{
public int rng;
public int def;
diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java
index b439cce..c88cbaf 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -31,7 +31,7 @@ import ch.asynk.tankontank.TankOnTank;
import ch.asynk.tankontank.game.GameFactory;
import ch.asynk.tankontank.game.GameFactory.UnitType;
-import ch.asynk.tankontank.engine.Map;
+import ch.asynk.tankontank.game.Map;
import ch.asynk.tankontank.engine.Pawn;
public class GameScreen implements Screen
@@ -69,12 +69,10 @@ public class GameScreen implements Screen
fps.setPosition( 10, Gdx.graphics.getHeight() - 40);
map = GameFactory.getMap(game.manager, GameFactory.MapType.MAP_A);
- map.setPosition(60, 60);
mapBatch = new SpriteBatch();
cam = new OrthographicCamera();
cam.setToOrtho(false);
- // cam.position.set((map.getWidth()/2), (map.getHeight()/2), 0);
mapViewport = new FitViewport(map.getWidth(), map.getHeight(), cam);
mapViewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);