summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r--core/src/ch/asynk/tankontank/game/Ctrl.java3
-rw-r--r--core/src/ch/asynk/tankontank/game/Hud.java73
-rw-r--r--core/src/ch/asynk/tankontank/game/Player.java55
-rw-r--r--core/src/ch/asynk/tankontank/game/battles/Factory.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/hud/Msg.java5
5 files changed, 70 insertions, 70 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Ctrl.java b/core/src/ch/asynk/tankontank/game/Ctrl.java
index 6957c5e..9c11472 100644
--- a/core/src/ch/asynk/tankontank/game/Ctrl.java
+++ b/core/src/ch/asynk/tankontank/game/Ctrl.java
@@ -60,6 +60,7 @@ public class Ctrl implements Disposable
this.hud = new Hud(this, game);
player.turnStart();
+ this.hud.update();
}
@Override
@@ -104,6 +105,7 @@ public class Ctrl implements Disposable
player = opponent;
opponent = tmp;
player.turnStart();
+ hud.update();
hud.notify(player.getName() + "'s turn");
}
@@ -111,6 +113,7 @@ public class Ctrl implements Disposable
{
if (map.activatedPawns.size() > 0) {
player.burnDownOneAp();
+ hud.update();
}
if (player.apExhausted())
nextPlayer();
diff --git a/core/src/ch/asynk/tankontank/game/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java
index 6155cac..c8ab144 100644
--- a/core/src/ch/asynk/tankontank/game/Hud.java
+++ b/core/src/ch/asynk/tankontank/game/Hud.java
@@ -19,13 +19,16 @@ import ch.asynk.tankontank.TankOnTank;
public class Hud implements Disposable
{
- private static final float OFFSET = 15f;
+ private static final float OFFSET =10f;
private static final float PADDING = 5f;
private final TankOnTank game;
private final Ctrl ctrl;
- private Bg bg;
+ private Bg actionsBg;
+ private Msg msg;
+
+ private Button btn;
public Button moveBtn;
public Button rotateBtn;
public Button promoteBtn;
@@ -33,8 +36,12 @@ public class Hud implements Disposable
public Button checkBtn;
public Button cancelBtn;
- private Button btn;
- private Msg msg;
+ private Image flag;
+ private Image usFlag;
+ private Image geFlag;
+ private Msg status;
+ private Image reinforcement;
+
private Vector2 corner;
@@ -53,11 +60,30 @@ public class Hud implements Disposable
checkBtn = new Button(atlas, "btn-check");
cancelBtn = new Button(atlas, "btn-cancel");
- bg = new Bg(atlas.findRegion("disabled"));
+ actionsBg = new Bg(atlas.findRegion("disabled"));
msg = new Msg(game.skin.getFont("default-font"), atlas.findRegion("disabled"));
- ctrl.player.setTopLeft(OFFSET, (Gdx.graphics.getHeight() - OFFSET));
- ctrl.opponent.setTopLeft(OFFSET, (Gdx.graphics.getHeight() - OFFSET));
+ usFlag = new Image(atlas.findRegion("us-flag"));
+ geFlag = new Image(atlas.findRegion("ge-flag"));
+ status = new Msg(game.skin.getFont("default-font"), atlas.findRegion("disabled"));
+ reinforcement= new Image(atlas.findRegion("reinforcement"));
+
+ float x = OFFSET;
+ float y = (Gdx.graphics.getHeight() - OFFSET);
+ usFlag.setPosition(x, (y - usFlag.getHeight()));
+ geFlag.setPosition(x, (y - geFlag.getHeight()));
+ status.setTopLeft((x + usFlag.getWidth() + 10), y, 10);
+ reinforcement.setPosition(x, usFlag.getY() - reinforcement.getHeight() - 0);
+ }
+
+ public void update()
+ {
+ status.write(ctrl.player.getStatus(), 0);
+ if (ctrl.player.getFaction() == Army.GE)
+ flag = geFlag;
+ else
+ flag = usFlag;
+ // TODO update reinforcement status
}
@Override
@@ -69,8 +95,13 @@ public class Hud implements Disposable
attackBtn.dispose();
checkBtn.dispose();
cancelBtn.dispose();
- bg.dispose();
+ actionsBg.dispose();
msg.dispose();
+
+ usFlag.dispose();
+ geFlag.dispose();
+ status.dispose();
+ reinforcement.dispose();
}
public void animate(float delta)
@@ -80,8 +111,11 @@ public class Hud implements Disposable
public void draw(Batch batch)
{
- ctrl.player.draw(batch);
- bg.draw(batch);
+ flag.draw(batch);
+ status.draw(batch);
+ reinforcement.draw(batch);
+
+ actionsBg.draw(batch);
if (moveBtn.visible) moveBtn.getImage().draw(batch);
if (rotateBtn.visible) rotateBtn.getImage().draw(batch);
if (promoteBtn.visible) promoteBtn.getImage().draw(batch);
@@ -133,7 +167,7 @@ public class Hud implements Disposable
if (check) y = setButton(checkBtn, x, y);
else checkBtn.hide();
- bg.set((x - PADDING), (corner.y - PADDING), (checkBtn.getWidth() + (2 * PADDING)), (y - corner.y));
+ actionsBg.set((x - PADDING), (corner.y - PADDING), (checkBtn.getWidth() + (2 * PADDING)), (y - corner.y));
}
public void hide()
@@ -144,13 +178,14 @@ public class Hud implements Disposable
attackBtn.hide();
checkBtn.hide();
cancelBtn.hide();
- bg.set(0, 0, 0, 0);
+ actionsBg.set(0, 0, 0, 0);
}
public boolean touchDown(float x, float y)
{
- if (ctrl.player.contains(x,y)) return true;
- if (!bg.contains(x,y)) return false;
+ if (flag.contains(x,y)) return true;
+ if (reinforcement.contains(x,y)) return true;
+ if (!actionsBg.contains(x,y)) return false;
btn = null;
@@ -178,11 +213,17 @@ public class Hud implements Disposable
if (btn != null)
btn.setOn();
- if (ctrl.player.contains(x,y)) {
+ if (flag.contains(x,y)) {
ctrl.endPlayerTurn();
return true;
}
- if (!bg.contains(x,y)) return false;
+
+ if (reinforcement.contains(x,y)) {
+ System.err.println("TODO reinforcement");
+ return true;
+ }
+
+ if (!actionsBg.contains(x,y)) return false;
if (btn == moveBtn)
ctrl.setState(State.StateType.MOVE);
diff --git a/core/src/ch/asynk/tankontank/game/Player.java b/core/src/ch/asynk/tankontank/game/Player.java
index 2feb243..86f9fb2 100644
--- a/core/src/ch/asynk/tankontank/game/Player.java
+++ b/core/src/ch/asynk/tankontank/game/Player.java
@@ -2,20 +2,10 @@ package ch.asynk.tankontank.game;
import java.util.Random;
-import com.badlogic.gdx.utils.Disposable;
-
-import com.badlogic.gdx.graphics.g2d.Batch;
-import com.badlogic.gdx.graphics.g2d.BitmapFont;
-import com.badlogic.gdx.graphics.g2d.TextureAtlas;
-import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
-
import ch.asynk.tankontank.TankOnTank;
import ch.asynk.tankontank.engine.Pawn;
-import ch.asynk.tankontank.engine.gfx.Image;
-import ch.asynk.tankontank.engine.gfx.Drawable;
-import ch.asynk.tankontank.game.hud.Msg;
-public class Player extends ch.asynk.tankontank.engine.Player implements Drawable, Disposable
+public class Player extends ch.asynk.tankontank.engine.Player
{
private static final float MOVE_TIME = 0.4f;
@@ -24,28 +14,23 @@ public class Player extends ch.asynk.tankontank.engine.Player implements Drawabl
private int turn;
private int apSpent;
private int actionPoints;
- private Image flag;
- private Msg status;
- public Player(final TankOnTank game, Army army, BitmapFont font, TextureAtlas atlas, String name, int n)
+ public Player(final TankOnTank game, Army army, int n)
{
super(army, n);
this.turn = 0;
this.actionPoints = 0;
- this.flag = new Image(atlas.findRegion(name));
- this.status = new Msg(font, atlas.findRegion("disabled"));
}
public String toString()
{
return faction + " AP: " + actionPoints +
- " units:" + units.size() + " casualties:" + casualties.size() + " reinforcement:" + reinforcement.size();
+ " units:" + units.size() + " casualties:" + casualties.size();
}
- @Override
- public void dispose()
+ public String getStatus()
{
- flag.dispose();
+ return "Turn: " + turn + " AP: " + (apSpent + 1);
}
public int getTurn()
@@ -61,7 +46,6 @@ public class Player extends ch.asynk.tankontank.engine.Player implements Drawabl
public void burnDownOneAp()
{
apSpent += 1;
- updateInfo();
if (apSpent > actionPoints) System.err.println("ERROR: spent too much AP, please report");
}
@@ -77,7 +61,6 @@ public class Player extends ch.asynk.tankontank.engine.Player implements Drawabl
for (Pawn pawn : units)
pawn.reset();
computeActionPoints();
- updateInfo();
}
public int d6()
@@ -96,11 +79,6 @@ public class Player extends ch.asynk.tankontank.engine.Player implements Drawabl
apSpent = 0;
}
- private void updateInfo()
- {
- status.write("Turn: " + turn + " AP: " + (apSpent + 1), flag.getX(), (flag.getY() - 40), 0, 10);
- }
-
public boolean canPromote(Pawn pawn)
{
if (pawn.isHq()) return false;
@@ -122,27 +100,4 @@ public class Player extends ch.asynk.tankontank.engine.Player implements Drawabl
}
return null;
}
-
- public boolean contains(float x, float y)
- {
- return flag.contains(x, y);
- }
-
- public void setTopLeft(float x, float y)
- {
- flag.setPosition(x, (y - flag.getHeight()));
- }
-
- @Override
- public void draw(Batch batch)
- {
- flag.draw(batch);
- status.draw(batch);
- }
-
- @Override
- public void drawDebug(ShapeRenderer debugShapes)
- {
- flag.drawDebug(debugShapes);
- }
}
diff --git a/core/src/ch/asynk/tankontank/game/battles/Factory.java b/core/src/ch/asynk/tankontank/game/battles/Factory.java
index a398de6..ca4575a 100644
--- a/core/src/ch/asynk/tankontank/game/battles/Factory.java
+++ b/core/src/ch/asynk/tankontank/game/battles/Factory.java
@@ -91,9 +91,9 @@ public class Factory implements Board.TileBuilder, Disposable
public Player getPlayer(Army army)
{
if (army == Army.US)
- return new Player(game, Army.US, game.skin.getFont("default-font"), hudAtlas, "us-flag", 10);
+ return new Player(game, Army.US, 10);
else
- return new Player(game, Army.GE, game.skin.getFont("default-font"), hudAtlas, "ge-flag", 10);
+ return new Player(game, Army.GE, 10);
}
public Unit getUnit(UnitId id)
diff --git a/core/src/ch/asynk/tankontank/game/hud/Msg.java b/core/src/ch/asynk/tankontank/game/hud/Msg.java
index a4d5a4b..69c834e 100644
--- a/core/src/ch/asynk/tankontank/game/hud/Msg.java
+++ b/core/src/ch/asynk/tankontank/game/hud/Msg.java
@@ -68,10 +68,11 @@ public class Msg extends Bg
write(text, position.getX(w), position.getY(h), duration, 10);
}
- public void setPosition(float x, float y, int padding)
+ public void setTopLeft(float x, float y, int padding)
{
+ TextBounds b = font.getBounds("A");
this.x = x;
- this.y = y;
+ this.y = (y - (2 * padding) - b.height);
this.padding = padding;
}