From db47a53fc4b3fb03445387991b125fbc98aaa693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 21 Sep 2014 04:26:13 +0200 Subject: Map: add touch and drag support for tests --- core/src/ch/asynk/tankontank/engine/Map.java | 4 ++++ core/src/ch/asynk/tankontank/engine/MapNode.java | 29 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) 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 animations = new Vector(2); private final Vector nextAnimations = new Vector(2); private final LinkedHashSet tilesToDraw = new LinkedHashSet(); @@ -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); + } + } } -- cgit v1.1-2-g2b99