summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/tankontank/game/GameFactory.java (renamed from core/src/ch/asynk/tankontank/game/UnitFactory.java)82
-rw-r--r--core/src/ch/asynk/tankontank/game/HexMapFactory.java56
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java14
3 files changed, 73 insertions, 79 deletions
diff --git a/core/src/ch/asynk/tankontank/game/UnitFactory.java b/core/src/ch/asynk/tankontank/game/GameFactory.java
index c2156ce..9dfdd6d 100644
--- a/core/src/ch/asynk/tankontank/game/UnitFactory.java
+++ b/core/src/ch/asynk/tankontank/game/GameFactory.java
@@ -1,11 +1,27 @@
package ch.asynk.tankontank.game;
import com.badlogic.gdx.assets.AssetManager;
+import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
-public class UnitFactory
+public class GameFactory
{
+ private static TextureAtlas usAtlas;
+ private static TextureAtlas geAtlas;
+
+ public static void init(AssetManager manager)
+ {
+ usAtlas = manager.get("images/us.pack", TextureAtlas.class);
+ geAtlas = manager.get("images/ge.pack", TextureAtlas.class);
+ }
+
+ public static void dispose()
+ {
+ usAtlas.dispose();
+ geAtlas.dispose();
+ }
+
public enum UnitType
{
GE_AT_GUN,
@@ -26,21 +42,6 @@ public class UnitFactory
US_WOLVERINE
}
- private static TextureAtlas usAtlas;
- private static TextureAtlas geAtlas;
-
- public static void init(AssetManager manager)
- {
- usAtlas = manager.get("images/us.pack", TextureAtlas.class);
- geAtlas = manager.get("images/ge.pack", TextureAtlas.class);
- }
-
- public static void dispose()
- {
- usAtlas.dispose();
- geAtlas.dispose();
- }
-
public static Unit getUnit(UnitType t)
{
Unit u = null;
@@ -94,4 +95,53 @@ public class UnitFactory
return u;
}
+
+ public enum MapType
+ {
+ MAP_A,
+ MAP_B
+ }
+
+ private static Map.Config config()
+ {
+ Map.Config cfg = new Map.Config();
+ cfg.cols = 11;
+ cfg.rows = 9;
+ cfg.x0 = 83;
+ cfg.y0 = 182;
+ cfg.h = 110;
+ cfg.dh = 53.6f;
+ cfg.w = 189;
+ cfg.dw = 94;
+ cfg.H = cfg.h + cfg.dh;
+ cfg.slope = (cfg.dh / (float) cfg.dw);
+
+ return cfg;
+ }
+
+ public static Map getMap(AssetManager manager, MapType t)
+ {
+ Map.Config cfg = config();
+
+ Hex[][] board = new Hex[cfg.rows][];
+ for (int i = 0; i < cfg.rows; i++) {
+ int c = cfg.cols;
+ if ((i % 2) == 1) c -= 1;
+ board[i] = new Hex[c];
+ for ( int j = 0; j < c; j ++)
+ board[i][j] = new MapHex(MapHex.Terrain.CLEAR);
+ }
+
+ Map m = null;
+ switch(t) {
+ case MAP_A:
+ m = new MapImage(config(), board, manager.get("images/map_a.png", Texture.class));
+ break;
+ case MAP_B:
+ m = new MapImage(config(), board, manager.get("images/map_b.png", Texture.class));
+ break;
+ }
+
+ return m;
+ }
}
diff --git a/core/src/ch/asynk/tankontank/game/HexMapFactory.java b/core/src/ch/asynk/tankontank/game/HexMapFactory.java
deleted file mode 100644
index ee2aa25..0000000
--- a/core/src/ch/asynk/tankontank/game/HexMapFactory.java
+++ /dev/null
@@ -1,56 +0,0 @@
-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
- }
-
- private static HexMap.Config config()
- {
- HexMap.Config cfg = new HexMap.Config();
- cfg.cols = 11;
- cfg.rows = 9;
- cfg.x0 = 83;
- cfg.y0 = 182;
- cfg.h = 110;
- cfg.dh = 53.6f;
- cfg.w = 189;
- cfg.dw = 94;
- cfg.H = cfg.h + cfg.dh;
- cfg.slope = (cfg.dh / (float) cfg.dw);
-
- return cfg;
- }
-
- public static HexMap getMap(AssetManager manager, MapType t)
- {
- HexMap.Config cfg = config();
-
- Hex[][] board = new Hex[cfg.rows][];
- for (int i = 0; i < cfg.rows; i++) {
- int c = cfg.cols;
- if ((i % 2) == 1) c -= 1;
- board[i] = new Hex[c];
- for ( int j = 0; j < c; j ++)
- board[i][j] = new MapHex(MapHex.Terrain.CLEAR);
- }
-
- HexMap m = null;
- switch(t) {
- case MAP_A:
- m = new HexMapImage(config(), board, manager.get("images/map_a.png", Texture.class));
- break;
- case MAP_B:
- m = new HexMapImage(config(), board, 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 cf946c3..8118489 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -25,14 +25,13 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import ch.asynk.tankontank.TankOnTank;
+import ch.asynk.tankontank.game.GameFactory;
+import ch.asynk.tankontank.game.GameFactory.UnitType;
import ch.asynk.tankontank.game.Pawn;
import ch.asynk.tankontank.game.HexMap;
import ch.asynk.tankontank.game.Hex;
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;
public class GameScreen extends AbstractScreen
{
@@ -62,10 +61,12 @@ public class GameScreen extends AbstractScreen
{
super(game);
+ GameFactory.init(game.manager);
+
fps = new Label("FPS: 0", game.skin);
fps.setPosition( 10, Gdx.graphics.getHeight() - 40);
- map = HexMapFactory.getMap(game.manager, HexMapFactory.MapType.MAP_A);
+ map = GameFactory.getMap(game.manager, GameFactory.MapType.MAP_A);
selectedHex = new Image(game.manager.get("images/hex.png", Texture.class));
selectedHex.setVisible(false);
@@ -77,7 +78,6 @@ public class GameScreen extends AbstractScreen
gameStage.addActor((HexMapImage) map);
gameStage.addActor(selectedHex);
- UnitFactory.init(game.manager);
Hex.Orientation o = Hex.Orientation.SOUTH_EAST;
addUnit(gameStage, UnitType.GE_AT_GUN, 1, 4, o);
@@ -106,7 +106,7 @@ public class GameScreen extends AbstractScreen
private void addUnit(Stage stage, UnitType t, int col, int row, Hex.Orientation o)
{
- Unit u = UnitFactory.getUnit(t);
+ Unit u = GameFactory.getUnit(t);
map.setPawnAt((Pawn) u, col, row, o);
stage.addActor(u);
}
@@ -230,7 +230,7 @@ public class GameScreen extends AbstractScreen
Gdx.app.debug("GameScreen", "dispose()");
hud.dispose();
gameStage.dispose();
- UnitFactory.dispose();
+ GameFactory.dispose();
game.unloadAssets();
}