diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-11-06 11:07:25 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-11-06 11:07:25 +0100 |
commit | 5a8b73c6b5337733450e611808f938e0cfb35296 (patch) | |
tree | 4584bebafb7cf7ae7634b231f4c20f703495d7db /core/src | |
parent | 5c6738cef7222a242b0d40241ee1c778c61866f1 (diff) | |
download | RustAndDust-5a8b73c6b5337733450e611808f938e0cfb35296.zip RustAndDust-5a8b73c6b5337733450e611808f938e0cfb35296.tar.gz |
GameScreen -> UnitDock: add drag and implement vertical slide of units
Diffstat (limited to 'core/src')
5 files changed, 42 insertions, 2 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Ctrl.java b/core/src/ch/asynk/rustanddust/game/Ctrl.java index 3b93ad8..8e05dad 100644 --- a/core/src/ch/asynk/rustanddust/game/Ctrl.java +++ b/core/src/ch/asynk/rustanddust/game/Ctrl.java @@ -250,6 +250,13 @@ public class Ctrl implements Disposable } + public boolean drag(int dx, int dy) + { + if (!blockHud && hud.drag(hudTouch.x, hudTouch.y, dx, dy)) + return true; + return false; + } + public void touchDown() { if (!blockHud && hud.touchDown(hudTouch.x, hudTouch.y)) diff --git a/core/src/ch/asynk/rustanddust/game/Hud.java b/core/src/ch/asynk/rustanddust/game/Hud.java index 8f9343c..661d4e9 100644 --- a/core/src/ch/asynk/rustanddust/game/Hud.java +++ b/core/src/ch/asynk/rustanddust/game/Hud.java @@ -150,6 +150,11 @@ public class Hud implements Disposable, Animation else msg.write(s, duration, position); } + public boolean drag(float x, float y, int dx, int dy) + { + return playerInfo.drag(x, y, dx, dy); + } + public boolean touchDown(float x, float y) { hit = null; diff --git a/core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java b/core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java index dd77c8e..ab8fe79 100644 --- a/core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java +++ b/core/src/ch/asynk/rustanddust/game/hud/PlayerInfo.java @@ -134,6 +134,14 @@ public class PlayerInfo implements Disposable, Drawable, Animation turns.blocked = blocked; } + public boolean drag(float x, float y, int dx, int dy) + { + if (!unitDock.hit(x, y)) + return false; + unitDock.drag(dx, dy); + return true; + } + public boolean touchDown(float x, float y) { hit = null; diff --git a/core/src/ch/asynk/rustanddust/game/hud/UnitDock.java b/core/src/ch/asynk/rustanddust/game/hud/UnitDock.java index 4e708c4..10d604e 100644 --- a/core/src/ch/asynk/rustanddust/game/hud/UnitDock.java +++ b/core/src/ch/asynk/rustanddust/game/hud/UnitDock.java @@ -29,6 +29,7 @@ public class UnitDock extends Bg implements Animation private float y; private float to; private float dx; + private float dy; private float step; private boolean show; private boolean mvtDone; @@ -55,6 +56,7 @@ public class UnitDock extends Bg implements Animation this.selected = new Sprite(selected); this.visible = false; this.dx = 0f; + this.dy = 0f; } @Override @@ -72,7 +74,7 @@ public class UnitDock extends Bg implements Animation private void compute() { transform.idt(); - transform.translate((rect.x + dx), (rect.y + rect.height), 0).scale(SCALE, SCALE, 0).translate(-rect.x, - (rect.y + rect.height), 0); + transform.translate((rect.x + dx), (rect.y + dy + rect.height), 0).scale(SCALE, SCALE, 0).translate(-rect.x, - (rect.y + rect.height), 0); point.set(rect.x, rect.y, 0).mul(transform); scaledRect.x = point.x; scaledRect.y = point.y; @@ -107,6 +109,16 @@ public class UnitDock extends Bg implements Animation return (visible && scaledRect.contains(x, y)); } + public void drag(int dx, int dy) + { + this.dy += dy; + if ((rect.y + this.dy + rect.height) < y) + this.dy = (y - rect.height - rect.y); + else if (scaledRect.y > SCISSORS_BOTTOM) + this.dy -= (scaledRect.y - SCISSORS_BOTTOM); + compute(); + } + public Unit select(float x, float y) { int i = (int) ((scaledRect.y + scaledRect.height - y) / (scaledRect.height / units.size())); @@ -129,6 +141,10 @@ public class UnitDock extends Bg implements Animation { if (!resize()) return; + if (dy != 0) { + dy = 0; + compute(); + } to = position.getX(rect.width * SCALE); show = true; diff --git a/core/src/ch/asynk/rustanddust/screens/GameScreen.java b/core/src/ch/asynk/rustanddust/screens/GameScreen.java index c369989..a3f20f1 100644 --- a/core/src/ch/asynk/rustanddust/screens/GameScreen.java +++ b/core/src/ch/asynk/rustanddust/screens/GameScreen.java @@ -85,8 +85,12 @@ public class GameScreen implements Screen public boolean touchDragged(int x, int y, int pointer) { dragged += 1; - cam.translate((dragPos.x - x), (dragPos.y - y)); + int dx = (int) (dragPos.x - x); + int dy = (int) (dragPos.y - y); dragPos.set(x, y); + cam.unprojectHud(x, y, ctrl.hudTouch); + if (!ctrl.drag(-dx, dy)) + cam.translate(dx, dy); return true; } @Override |