summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-21 04:26:13 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-21 04:26:13 +0200
commitdb47a53fc4b3fb03445387991b125fbc98aaa693 (patch)
tree3ad0afc2eaa67e9850fb5b70d461c526fd3a6c2b
parentfca82703546c3d88c8683ed472ef8ea56e9e1d6d (diff)
downloadRustAndDust-db47a53fc4b3fb03445387991b125fbc98aaa693.zip
RustAndDust-db47a53fc4b3fb03445387991b125fbc98aaa693.tar.gz
Map: add touch and drag support for tests
-rw-r--r--core/src/ch/asynk/tankontank/engine/Map.java4
-rw-r--r--core/src/ch/asynk/tankontank/engine/MapNode.java29
2 files changed, 33 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Map.java b/core/src/ch/asynk/tankontank/engine/Map.java
index 8e5fcbf..253edf0 100644
--- a/core/src/ch/asynk/tankontank/engine/Map.java
+++ b/core/src/ch/asynk/tankontank/engine/Map.java
@@ -40,4 +40,8 @@ public interface Map extends Drawable, Disposable
public float h; // square height : s + dh
public float slope; // north-west side slope : (dh / (float) dw)
}
+
+ public void touchUp(float x, float y);
+ public void touchDown(float x, float y);
+ public boolean drag(float dx, float dy);
}
diff --git a/core/src/ch/asynk/tankontank/engine/MapNode.java b/core/src/ch/asynk/tankontank/engine/MapNode.java
index 740074e..bf9928a 100644
--- a/core/src/ch/asynk/tankontank/engine/MapNode.java
+++ b/core/src/ch/asynk/tankontank/engine/MapNode.java
@@ -31,6 +31,9 @@ public class MapNode extends Image implements Map
private Matrix4 prevTransform;
private Matrix4 nextTransform;
+ private Pawn currentPawn;
+ private GridPoint2 currentHex = new GridPoint2(-1, -1);
+
private final Vector<Animation> animations = new Vector<Animation>(2);
private final Vector<Animation> nextAnimations = new Vector<Animation>(2);
private final LinkedHashSet<Tile> tilesToDraw = new LinkedHashSet<Tile>();
@@ -277,5 +280,31 @@ public class MapNode extends Image implements Map
return hex;
}
+
+ @Override
+ public boolean drag(float dx, float dy)
+ {
+ if (currentPawn == null) return false;
+ currentPawn.translate(dx, dy);
+ return true;
+ }
+
+ @Override
+ public void touchDown(float x, float y)
+ {
+ getHexAt(currentHex, x, y);
+ if (currentHex.x != -1) {
+ currentPawn = getTopPawnAt(currentHex);
+ }
+ }
+
+ @Override
+ public void touchUp(float x, float y)
+ {
+ getHexAt(currentHex, x, y);
+ if (currentPawn != null) {
+ movePawnTo(currentPawn, currentHex);
+ }
+ }
}