diff options
Diffstat (limited to 'core/src/ch/asynk/rustanddust')
14 files changed, 72 insertions, 158 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Ctrl.java b/core/src/ch/asynk/rustanddust/game/Ctrl.java index 024bd02..d75ef94 100644 --- a/core/src/ch/asynk/rustanddust/game/Ctrl.java +++ b/core/src/ch/asynk/rustanddust/game/Ctrl.java @@ -2,8 +2,6 @@ package ch.asynk.rustanddust.game; import com.badlogic.gdx.utils.Disposable; -import com.badlogic.gdx.math.Vector3; - import ch.asynk.rustanddust.RustAndDust; import ch.asynk.rustanddust.ui.Position; import ch.asynk.rustanddust.game.State.StateType; @@ -28,9 +26,7 @@ public class Ctrl implements Disposable public Hud hud; public boolean blockMap; public boolean blockHud; - - public Vector3 mapTouch = new Vector3(); - public Vector3 hudTouch = new Vector3(); + private Hex touchedHex; private State selectState; private State pathState; @@ -71,6 +67,7 @@ public class Ctrl implements Disposable this.blockMap = false; this.blockHud = false; + this.touchedHex = null; this.map = battle.setup(); this.hud = new Hud(game); @@ -92,28 +89,27 @@ public class Ctrl implements Disposable // INPUTS - public boolean drag(int dx, int dy) + public boolean drag(float x, float y, int dx, int dy) { - if (!blockHud && hud.drag(hudTouch.x, hudTouch.y, dx, dy)) + if (!blockHud && hud.drag(x, y, dx, dy)) return true; return false; } - public void touchDown() + public void touchDown(float hudX, float hudY, float mapX, float mapY) { boolean inAnimation = (this.stateType == StateType.ANIMATION); - if (!blockHud && hud.hit(hudTouch.x, hudTouch.y, inAnimation)) + if (!blockHud && hud.hit(hudX, hudY, inAnimation)) return; - if (!blockMap && state.downInMap(mapTouch.x, mapTouch.y)) - state.touchDown(); + touchedHex = (blockMap ? null : map.getHexAt(mapX, mapY)); } - public void touchUp() + public void touchUp(float hudX, float hudY, float mapX, float mapY) { - if (!blockMap && state.upInMap(mapTouch.x, mapTouch.y)) - state.touchUp(); + if (!blockMap && (touchedHex == map.getHexAt(mapX, mapY))) + state.touch(touchedHex); } // Map callbacks @@ -153,11 +149,8 @@ public class Ctrl implements Disposable public void showEntryZone() { - if ((stateType == StateType.DEPLOYMENT) || (stateType == StateType.REINFORCEMENT)) { - state.downInMap(-1, -1); - state.upInMap(-1, -1); - state.touchUp(); - } + if ((stateType == StateType.DEPLOYMENT) || (stateType == StateType.REINFORCEMENT)) + state.touch(null); } public void endDeployment() diff --git a/core/src/ch/asynk/rustanddust/game/State.java b/core/src/ch/asynk/rustanddust/game/State.java index 386df8b..73a0f5b 100644 --- a/core/src/ch/asynk/rustanddust/game/State.java +++ b/core/src/ch/asynk/rustanddust/game/State.java @@ -26,11 +26,5 @@ public interface State public StateType execute(); - public void touchDown(); - - public void touchUp(); - - public boolean downInMap(float x, float y); - - public boolean upInMap(float x, float y); + public void touch(Hex hex); } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateAnimation.java b/core/src/ch/asynk/rustanddust/game/states/StateAnimation.java index 41831e0..4b50bec 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateAnimation.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateAnimation.java @@ -24,14 +24,4 @@ public class StateAnimation extends StateCommon { return StateType.DONE; } - - @Override - public void touchDown() - { - } - - @Override - public void touchUp() - { - } } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateBreak.java b/core/src/ch/asynk/rustanddust/game/states/StateBreak.java index 56e8ba6..45b1937 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateBreak.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateBreak.java @@ -1,6 +1,7 @@ package ch.asynk.rustanddust.game.states; import ch.asynk.rustanddust.engine.Orientation; +import ch.asynk.rustanddust.game.Hex; import ch.asynk.rustanddust.game.Unit; import ch.asynk.rustanddust.game.hud.ActionButtons.Buttons; @@ -41,25 +42,20 @@ public class StateBreak extends StateCommon } @Override - public void touchDown() - { - } - - @Override - public void touchUp() + public void touch(Hex hex) { // TODO : cancel preview move before showing rotation if (activeUnit == null) { - Unit unit = upHex.getUnit(); + Unit unit = hex.getUnit(); if (map.unitsBreakThroughContains(unit)) { activeUnit = unit; - map.hexMoveShow(upHex); + map.hexMoveShow(hex); map.hexMoveShow(to); map.hexDirectionsShow(to); map.unitsBreakThroughHide(); } } else { - o = Orientation.fromAdj(to, upHex); + o = Orientation.fromAdj(to, hex); if (o == Orientation.KEEP) return; diff --git a/core/src/ch/asynk/rustanddust/game/states/StateCommon.java b/core/src/ch/asynk/rustanddust/game/states/StateCommon.java index 97aecfc..8b6efed 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateCommon.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateCommon.java @@ -16,8 +16,6 @@ public abstract class StateCommon implements State protected static Map map; protected static Hex selectedHex = null; - protected static Hex downHex = null; - protected static Hex upHex = null; protected static Hex to = null; protected boolean isEnemy; @@ -31,20 +29,6 @@ public abstract class StateCommon implements State map = game.ctrl.map; } - @Override - public boolean downInMap(float x, float y) - { - downHex = map.getHexAt(x, y); - return (downHex != null); - } - - @Override - public boolean upInMap(float x, float y) - { - upHex = map.getHexAt(x, y); - return (upHex != null); - } - protected boolean hasUnit() { return (selectedUnit != null); @@ -64,4 +48,7 @@ public abstract class StateCommon implements State map.unitsTargetHide(); map.unitsMoveableHide(); } + + @Override + public void touch(Hex hex) { } } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java b/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java index 14c015e..0afc4ee 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateDeployment.java @@ -53,26 +53,21 @@ public class StateDeployment extends StateCommon } @Override - public void touchDown() - { - } - - @Override - public void touchUp() + public void touch(Hex hex) { Unit unit = ctrl.hud.playerInfo.unitDock.selectedUnit; - if (!completed && (unit != null) && (unit != activeUnit)) { + if (hex == null) { showEntryZone(unit); } else if (selectedUnit != null) { - deployUnit(Orientation.fromAdj(selectedHex, upHex)); - } else if (!completed && (entryZone != null) && (upHex != null)) { - if (upHex.isEmpty() && entryZone.contains(upHex)) { - showUnit(activeUnit, upHex); + deployUnit(Orientation.fromAdj(selectedHex, hex)); + } else if (!completed && (entryZone != null) && (hex != null)) { + if (hex.isEmpty() && entryZone.contains(hex)) { + showUnit(activeUnit, hex); } } else { - unit = upHex.getUnit(); + unit = hex.getUnit(); if (deployedUnits.contains(unit)) - showRotation(unit, upHex); + showRotation(unit, hex); } } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateEngage.java b/core/src/ch/asynk/rustanddust/game/states/StateEngage.java index 582e5dd..4bc3287 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateEngage.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateEngage.java @@ -1,5 +1,6 @@ package ch.asynk.rustanddust.game.states; +import ch.asynk.rustanddust.game.Hex; import ch.asynk.rustanddust.game.Unit; import ch.asynk.rustanddust.RustAndDust; @@ -20,8 +21,7 @@ public class StateEngage extends StateCommon map.unitsTargetShow(); if (to != null) { // quick fire -> replay touchUp - upHex = to; - touchUp(); + touch(to); } selectedUnit.showAttack(); map.hexSelect(selectedHex); @@ -67,14 +67,9 @@ public class StateEngage extends StateCommon } @Override - public void touchDown() + public void touch(Hex hex) { - } - - @Override - public void touchUp() - { - Unit unit = upHex.getUnit(); + Unit unit = hex.getUnit(); // activeUnit is the target, selectedTarget is the engagement leader if (unit == selectedUnit) { @@ -82,7 +77,7 @@ public class StateEngage extends StateCommon } else if ((activeUnit == null) && map.unitsTargetContains(unit)) { // ctrl.hud.notify("Engage " + unit); map.unitsTargetHide(); - to = upHex; + to = hex; activeUnit = unit; activeUnit.showTarget(); map.collectAssists(selectedUnit, activeUnit, ctrl.battle.getPlayer().units); diff --git a/core/src/ch/asynk/rustanddust/game/states/StateMove.java b/core/src/ch/asynk/rustanddust/game/states/StateMove.java index 8c3c68e..67fb673 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateMove.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateMove.java @@ -30,8 +30,7 @@ public class StateMove extends StateCommon map.collectUpdate(activeUnit); if (to != null) { // quick move -> replay touchUp - upHex = to; - touchUp(); + touch(to); } else checkExit(activeUnit, activeUnit.getHex()); } else { @@ -92,14 +91,9 @@ public class StateMove extends StateCommon } @Override - public void touchDown() + public void touch(Hex hex) { - } - - @Override - public void touchUp() - { - if (upHex == activeUnit.getHex()) { + if (hex == activeUnit.getHex()) { if (to != null) map.pathHide(to); to = null; @@ -110,19 +104,19 @@ public class StateMove extends StateCommon int s = map.pathsSize(); - Unit unit = upHex.getUnit(); + Unit unit = hex.getUnit(); if (map.unitsMoveableContains(unit)) { if(unit != activeUnit) changeUnit(unit); - } else if ((s == 0) && map.movesContains(upHex)) { - s = collectPaths(upHex); - } else if (map.pathsContains(upHex)) { - s = togglePoint(downHex, s); + } else if ((s == 0) && map.movesContains(hex)) { + s = collectPaths(hex); + } else if (map.pathsContains(hex)) { + s = togglePoint(hex, s); } if (s == 1) { - if (!checkExit(activeUnit, upHex)) + if (!checkExit(activeUnit, hex)) ctrl.setState(StateType.ROTATE); } } diff --git a/core/src/ch/asynk/rustanddust/game/states/StatePromote.java b/core/src/ch/asynk/rustanddust/game/states/StatePromote.java index e80ebec..b991949 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StatePromote.java +++ b/core/src/ch/asynk/rustanddust/game/states/StatePromote.java @@ -27,14 +27,4 @@ public class StatePromote extends StateCommon { return StateType.DONE; } - - @Override - public void touchDown() - { - } - - @Override - public void touchUp() - { - } } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java b/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java index 304e2b5..8c89f3b 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateReinforcement.java @@ -42,18 +42,13 @@ public class StateReinforcement extends StateCommon } @Override - public void touchDown() - { - } - - @Override - public void touchUp() + public void touch(Hex hex) { Unit unit = ctrl.hud.playerInfo.unitDock.selectedUnit; - if ((unit != null) && (unit != activeUnit)) + if (hex == null) changeUnit(unit); - else if ((entryZone != null) && upHex.isEmpty() && entryZone.contains(upHex)) - unitEnter(activeUnit); + else if ((entryZone != null) && hex.isEmpty() && entryZone.contains(hex)) + unitEnter(activeUnit, hex); else ctrl.setState(StateType.SELECT); } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateRotate.java b/core/src/ch/asynk/rustanddust/game/states/StateRotate.java index 2e9b520..0331cdb 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateRotate.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateRotate.java @@ -2,6 +2,8 @@ package ch.asynk.rustanddust.game.states; import ch.asynk.rustanddust.engine.Orientation; +import ch.asynk.rustanddust.game.Hex; + import ch.asynk.rustanddust.RustAndDust; public class StateRotate extends StateCommon @@ -77,16 +79,11 @@ public class StateRotate extends StateCommon } @Override - public void touchDown() - { - } - - @Override - public void touchUp() + public void touch(Hex hex) { if (rotationSet) return; - Orientation o = Orientation.fromAdj(to, upHex); + Orientation o = Orientation.fromAdj(to, hex); if (o == Orientation.KEEP) { ctrl.setState(StateType.ABORT); return; diff --git a/core/src/ch/asynk/rustanddust/game/states/StateSelect.java b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java index e2cfef8..797623c 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateSelect.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateSelect.java @@ -43,23 +43,18 @@ public class StateSelect extends StateCommon } @Override - public void touchDown() - { - } - - @Override - public void touchUp() + public void touch(Hex hex) { if (!isEnemy) { - if (map.movesContains(upHex)) { + if (map.movesContains(hex)) { // quick move - to = upHex; + to = hex; ctrl.setState(StateType.MOVE); return; } - if (map.unitsTargetContains(upHex.getUnit())) { + if (map.unitsTargetContains(hex.getUnit())) { // quick fire - to = upHex; + to = hex; ctrl.setState(StateType.ENGAGE); return; } @@ -69,12 +64,12 @@ public class StateSelect extends StateCommon map.hexUnselect(selectedHex); hidePossibilities(); - if (upHex.isOffMap()) { + if (hex.isOffMap()) { selectedUnit = null; return; } - Unit unit = upHex.getUnit(); + Unit unit = hex.getUnit(); if (unit == null) { isEnemy = false; @@ -88,15 +83,15 @@ public class StateSelect extends StateCommon if (!isEnemy && (unit == selectedUnit) && unit.canMove()) { if (unit.isHq() && (map.unitsMoveableSize() > 1)) { ctrl.hud.notify("HQ activation"); - select(upHex, unit, isEnemy); + select(hex, unit, isEnemy); ctrl.setState(StateType.MOVE); } else { // quick rotate - to = upHex; + to = hex; ctrl.setState(StateType.ROTATE); } } else { - select(upHex, unit, isEnemy); + select(hex, unit, isEnemy); ctrl.hud.notify(selectedUnit.toString(), Position.TOP_CENTER); } } diff --git a/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java b/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java index a17f58b..bbdfb4c 100644 --- a/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java +++ b/core/src/ch/asynk/rustanddust/game/states/StateWithdraw.java @@ -33,16 +33,6 @@ public class StateWithdraw extends StateCommon return StateType.ANIMATION; } - @Override - public void touchDown() - { - } - - @Override - public void touchUp() - { - } - private StateType withdraw(Unit unit) { Zone exitZone = ctrl.battle.getExitZone(unit); diff --git a/core/src/ch/asynk/rustanddust/screens/GameScreen.java b/core/src/ch/asynk/rustanddust/screens/GameScreen.java index 53f079a..6c58c1b 100644 --- a/core/src/ch/asynk/rustanddust/screens/GameScreen.java +++ b/core/src/ch/asynk/rustanddust/screens/GameScreen.java @@ -14,6 +14,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.math.Vector3; import ch.asynk.rustanddust.RustAndDust; @@ -44,6 +45,8 @@ public class GameScreen implements Screen private boolean blocked; private float inputDelay = 0f; private Vector2 dragPos = new Vector2(); + private Vector3 hudTouch = new Vector3(); + private Vector3 mapTouch = new Vector3(); public GameScreen(final RustAndDust game) { @@ -87,8 +90,8 @@ public class GameScreen implements Screen 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.unprojectHud(x, y, hudTouch); + if (!ctrl.drag(hudTouch.x, hudTouch.y, -dx, dy)) cam.translate(dx, dy); return true; } @@ -98,9 +101,9 @@ public class GameScreen implements Screen if (blocked) return true; if (button == Input.Buttons.LEFT) { dragPos.set(x, y); - cam.unproject(x, y, ctrl.mapTouch); - cam.unprojectHud(x, y, ctrl.hudTouch); - ctrl.touchDown(); + cam.unproject(x, y, mapTouch); + cam.unprojectHud(x, y, hudTouch); + ctrl.touchDown(hudTouch.x, hudTouch.y, mapTouch.x, mapTouch.y); } return true; } @@ -114,9 +117,9 @@ public class GameScreen implements Screen } dragged = 0; if (button == Input.Buttons.LEFT) { - cam.unproject(x, y, ctrl.mapTouch); - cam.unprojectHud(x, y, ctrl.hudTouch); - ctrl.touchUp(); + cam.unproject(x, y, mapTouch); + cam.unprojectHud(x, y, hudTouch); + ctrl.touchUp(hudTouch.x, hudTouch.y, mapTouch.x, mapTouch.y); } return true; } |