summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-16 14:37:28 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-16 14:37:28 +0200
commitfc9c92b3a1441066c0b9b78858b6bbb0b4848574 (patch)
tree5585b4b6b3075daa8ee4aadb9c050317776288ba /core/src/ch
parent550bb87f52a724d0e4df71e9fccab985d18460b6 (diff)
downloadRustAndDust-fc9c92b3a1441066c0b9b78858b6bbb0b4848574.zip
RustAndDust-fc9c92b3a1441066c0b9b78858b6bbb0b4848574.tar.gz
add game/HexMapFactory
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/tankontank/game/HexMapFactory.java28
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java19
2 files changed, 39 insertions, 8 deletions
diff --git a/core/src/ch/asynk/tankontank/game/HexMapFactory.java b/core/src/ch/asynk/tankontank/game/HexMapFactory.java
new file mode 100644
index 0000000..18706bf
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/HexMapFactory.java
@@ -0,0 +1,28 @@
+package ch.asynk.tankontank.game;
+
+import com.badlogic.gdx.assets.AssetManager;
+import com.badlogic.gdx.graphics.Texture;
+
+public class HexMapFactory
+{
+ public enum MapType
+ {
+ MAP_A,
+ MAP_B
+ }
+
+ public static HexMap getMap(AssetManager manager, MapType t)
+ {
+ HexMap m = null;
+ switch(t) {
+ case MAP_A:
+ m = new HexMapImage(11, 9, manager.get("images/map_a.png", Texture.class));
+ break;
+ case MAP_B:
+ m = new HexMapImage(11, 9, manager.get("images/map_b.png", Texture.class));
+ break;
+ }
+
+ return m;
+ }
+}
diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java
index 98cd1a2..4c0b4ef 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -27,6 +27,8 @@ import com.badlogic.gdx.utils.viewport.ScreenViewport;
import ch.asynk.tankontank.TankOnTank;
import ch.asynk.tankontank.game.Pawn;
import ch.asynk.tankontank.game.HexMap;
+import ch.asynk.tankontank.game.HexMapImage;
+import ch.asynk.tankontank.game.HexMapFactory;
import ch.asynk.tankontank.game.Unit;
import ch.asynk.tankontank.game.UnitFactory;
import ch.asynk.tankontank.game.UnitFactory.UnitType;
@@ -62,7 +64,7 @@ public class GameScreen extends AbstractScreen
fps = new Label("FPS: 0", game.skin);
fps.setPosition( 10, Gdx.graphics.getHeight() - 40);
- map = new HexMap(11, 9, game.manager.get("images/map_a.png", Texture.class));
+ map = HexMapFactory.getMap(game.manager, HexMapFactory.MapType.MAP_A);
selectedHex = new Image(game.manager.get("images/hex.png", Texture.class));
selectedHex.setVisible(false);
@@ -71,7 +73,7 @@ public class GameScreen extends AbstractScreen
// cam.position.set((map.getWidth()/2), (map.getHeight()/2), 0);
gameStage = new Stage(new FitViewport(map.getWidth(), map.getHeight(), cam));
- gameStage.addActor(map);
+ gameStage.addActor((HexMapImage) map);
gameStage.addActor(selectedHex);
UnitFactory.init(game.manager, map);
@@ -134,9 +136,9 @@ public class GameScreen extends AbstractScreen
} else {
draggedPawn.moveBy(deltaX, deltaY);
cam.unproject(touchPos.set(x, y, 0));
- map.getCellAt(cell, touchPos.x, touchPos.y);
- map.setImageCenterAt(selectedHex, cell);
-
+ map.getHexAt(cell, touchPos.x, touchPos.y);
+ Vector2 v = map.getHexCenterAt(cell);
+ selectedHex.setCenterPosition(v.x, v.y);
}
return true;
}
@@ -146,10 +148,11 @@ public class GameScreen extends AbstractScreen
if (button == Input.Buttons.LEFT) {
dragPos.set(x, y);
cam.unproject(touchPos.set(x, y, 0));
- map.getCellAt(cell, touchPos.x, touchPos.y);
+ map.getHexAt(cell, touchPos.x, touchPos.y);
draggedPawn = map.getTopPawnAt(cell);
if (draggedPawn != null) draggedPawn.setZIndex(DRAGGED_Z_INDEX);
- map.setImageCenterAt(selectedHex, cell);
+ Vector2 v = map.getHexCenterAt(cell);
+ selectedHex.setCenterPosition(v.x, v.y);
selectedHex.setVisible(true);
}
return true;
@@ -160,7 +163,7 @@ public class GameScreen extends AbstractScreen
if (button == Input.Buttons.LEFT) {
cam.unproject(touchPos.set(x, y, 0));
if (draggedPawn != null) {
- map.getCellAt(cell, touchPos.x, touchPos.y);
+ map.getHexAt(cell, touchPos.x, touchPos.y);
draggedPawn.moveTo(cell);
}
selectedHex.setVisible(false);