summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/game/HexMap.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/Pawn.java80
-rw-r--r--core/src/ch/asynk/tankontank/game/PawnImage.java82
-rw-r--r--core/src/ch/asynk/tankontank/game/Unit.java2
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java3
5 files changed, 101 insertions, 68 deletions
diff --git a/core/src/ch/asynk/tankontank/game/HexMap.java b/core/src/ch/asynk/tankontank/game/HexMap.java
index 7aced56..32f3fb6 100644
--- a/core/src/ch/asynk/tankontank/game/HexMap.java
+++ b/core/src/ch/asynk/tankontank/game/HexMap.java
@@ -96,7 +96,7 @@ public class HexMap extends Image
private void setPawnOn(Pawn pawn, int col, int row, int angle)
{
- GridPoint3 prev = pawn.getHex();
+ GridPoint3 prev = pawn.getBoardPosition();
if (prev != null) removePawnFrom(pawn, prev.x, prev.y);
Vector2 pos = getPawnPosAt(pawn, col, row);
diff --git a/core/src/ch/asynk/tankontank/game/Pawn.java b/core/src/ch/asynk/tankontank/game/Pawn.java
index 804097f..519a56e 100644
--- a/core/src/ch/asynk/tankontank/game/Pawn.java
+++ b/core/src/ch/asynk/tankontank/game/Pawn.java
@@ -1,83 +1,33 @@
package ch.asynk.tankontank.game;
-import java.util.ArrayDeque;
-
-import com.badlogic.gdx.graphics.g2d.TextureRegion;
-import com.badlogic.gdx.scenes.scene2d.ui.Image;
-import com.badlogic.gdx.scenes.scene2d.actions.Actions;
-import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
-
-import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.math.GridPoint3;
-public class Pawn extends Image
+public interface Pawn
{
- public static final int DRAGGED_Z_INDEX = 10;
- private static final float MOVE_TIME = 0.3f;
+ // Gfx related
+
+ public float getHeight();
- private HexMap map;
- private ArrayDeque<GridPoint3> path = new ArrayDeque<GridPoint3>();
+ public float getWidth();
- public Pawn(TextureRegion region, HexMap map)
- {
- super(region);
- this.map = map;
- setOrigin((getWidth() / 2.f), (getHeight() / 2.f));
- }
+ public void moveBy(float x, float y);
- public GridPoint3 getHex()
- {
- if (path.size() == 0) return null;
- return path.getFirst();
- }
+ public void setPosition(float x, float y);
- public void moveTo(GridPoint2 hex)
- {
- moveTo(new GridPoint3(hex.x, hex.y, (int) getRotation()));
- }
+ public void setRotation(float angle);
- public void moveTo(int col, int row, int angle)
- {
- moveTo(new GridPoint3(col, row, angle));
- }
+ public void setZIndex(int zIndex);
- private void moveTo(GridPoint3 hex)
- {
- if ((hex.x == -1) || (hex.y == -1)) {
- resetMoves();
- } else {
- map.setPawnOn(this, hex);
- path.push(hex);
- }
- }
+ // Board related
- public void resetMoves()
- {
- final Pawn self = this;
- final GridPoint3 finalHex = path.getLast();
+ public GridPoint3 getBoardPosition();
- SequenceAction seq = new SequenceAction();
- while(path.size() != 0) {
- Vector2 v = map.getPawnPosAt(this, path.pop());
- seq.addAction(Actions.moveTo(v.x, v.y, MOVE_TIME));
- }
+ public void moveTo(GridPoint2 hex);
- seq.addAction( Actions.run(new Runnable() {
- @Override
- public void run() {
- map.setPawnOn(self, finalHex);
- path.push(finalHex);
- }
- }));
+ public void moveTo(int col, int row, int angle);
- addAction(seq);
- }
+ public void resetMoves();
- public void moveDone()
- {
- GridPoint3 hex = path.pop();
- path.clear();
- path.push(hex);
- }
+ public void moveDone();
}
diff --git a/core/src/ch/asynk/tankontank/game/PawnImage.java b/core/src/ch/asynk/tankontank/game/PawnImage.java
new file mode 100644
index 0000000..f98f86b
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/PawnImage.java
@@ -0,0 +1,82 @@
+package ch.asynk.tankontank.game;
+
+import java.util.ArrayDeque;
+
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.scenes.scene2d.ui.Image;
+import com.badlogic.gdx.scenes.scene2d.actions.Actions;
+import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;
+
+import com.badlogic.gdx.math.Vector2;
+import com.badlogic.gdx.math.GridPoint2;
+import com.badlogic.gdx.math.GridPoint3;
+
+public class PawnImage extends Image implements Pawn
+{
+ private static final float MOVE_TIME = 0.3f;
+
+ private HexMap map;
+ private ArrayDeque<GridPoint3> path = new ArrayDeque<GridPoint3>();
+
+ public PawnImage(TextureRegion region, HexMap map)
+ {
+ super(region);
+ this.map = map;
+ setOrigin((getWidth() / 2.f), (getHeight() / 2.f));
+ }
+
+ public GridPoint3 getBoardPosition()
+ {
+ if (path.size() == 0) return null;
+ return path.getFirst();
+ }
+
+ public void moveTo(GridPoint2 hex)
+ {
+ moveTo(new GridPoint3(hex.x, hex.y, (int) getRotation()));
+ }
+
+ public void moveTo(int col, int row, int angle)
+ {
+ moveTo(new GridPoint3(col, row, angle));
+ }
+
+ private void moveTo(GridPoint3 hex)
+ {
+ if ((hex.x == -1) || (hex.y == -1)) {
+ resetMoves();
+ } else {
+ map.setPawnOn(this, hex);
+ path.push(hex);
+ }
+ }
+
+ public void resetMoves()
+ {
+ final Pawn self = this;
+ final GridPoint3 finalHex = path.getLast();
+
+ SequenceAction seq = new SequenceAction();
+ while(path.size() != 0) {
+ Vector2 v = map.getPawnPosAt(this, path.pop());
+ seq.addAction(Actions.moveTo(v.x, v.y, MOVE_TIME));
+ }
+
+ seq.addAction( Actions.run(new Runnable() {
+ @Override
+ public void run() {
+ map.setPawnOn(self, finalHex);
+ path.push(finalHex);
+ }
+ }));
+
+ addAction(seq);
+ }
+
+ public void moveDone()
+ {
+ GridPoint3 hex = path.pop();
+ path.clear();
+ path.push(hex);
+ }
+}
diff --git a/core/src/ch/asynk/tankontank/game/Unit.java b/core/src/ch/asynk/tankontank/game/Unit.java
index 7487799..6606c14 100644
--- a/core/src/ch/asynk/tankontank/game/Unit.java
+++ b/core/src/ch/asynk/tankontank/game/Unit.java
@@ -2,7 +2,7 @@ package ch.asynk.tankontank.game;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
-public class Unit extends Pawn
+public class Unit extends PawnImage
{
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 96771a2..dff9899 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -36,6 +36,7 @@ public class GameScreen extends AbstractScreen
static private final float ZOOM_MAX = 0.2f;
static private final float ZOOM_GESTURE_FACTOR = .01f;
static private final float ZOOM_SCROLL_FACTOR = .1f;
+ private static final int DRAGGED_Z_INDEX = 10;
private float maxZoomOut;
final OrthographicCamera cam;
@@ -147,7 +148,7 @@ public class GameScreen extends AbstractScreen
cam.unproject(touchPos.set(x, y, 0));
map.getCellAt(cell, touchPos.x, touchPos.y);
draggedPawn = map.getTopPawnAt(cell);
- if (draggedPawn != null) draggedPawn.setZIndex(Pawn.DRAGGED_Z_INDEX);
+ if (draggedPawn != null) draggedPawn.setZIndex(DRAGGED_Z_INDEX);
map.setImageCenterAt(selectedHex, cell);
selectedHex.setVisible(true);
}