diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-28 10:41:42 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-28 10:41:42 +0100 |
commit | 65b0a1489edfb0c9faaea498de2d4c8111a6974a (patch) | |
tree | 9dc4ba43c836f51eb59a7eb3559c98c814e97257 | |
parent | 1f2d589c6d97a9be7eed24c030642aac99df6813 (diff) | |
download | RustAndDust-65b0a1489edfb0c9faaea498de2d4c8111a6974a.zip RustAndDust-65b0a1489edfb0c9faaea498de2d4c8111a6974a.tar.gz |
States: use Hex instead of GridPoint2
6 files changed, 75 insertions, 86 deletions
diff --git a/core/src/ch/asynk/tankontank/game/states/StateAnimation.java b/core/src/ch/asynk/tankontank/game/states/StateAnimation.java index d5aaff0..ec815aa 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateAnimation.java +++ b/core/src/ch/asynk/tankontank/game/states/StateAnimation.java @@ -14,8 +14,8 @@ public class StateAnimation extends StateCommon public void leave(StateType nextState) { if (nextState != StateType.SELECT) { - from.set(-1, -1); - to.set(-1, -1); + from = null; + to = null; } } diff --git a/core/src/ch/asynk/tankontank/game/states/StateAttack.java b/core/src/ch/asynk/tankontank/game/states/StateAttack.java index f02a2f7..5587a45 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateAttack.java +++ b/core/src/ch/asynk/tankontank/game/states/StateAttack.java @@ -1,7 +1,5 @@ package ch.asynk.tankontank.game.states; -import com.badlogic.gdx.math.GridPoint2; - import ch.asynk.tankontank.engine.Pawn; import ch.asynk.tankontank.game.State.StateType; @@ -17,13 +15,13 @@ public class StateAttack extends StateCommon if (fromSelect) { activePawn = null; // use selectedHex and selectedPawn - from.set(selectedHex); + from = selectedHex; map.showPossibleTargets(false); - map.buildPossibleTargets(selectedPawn, from, ctrl.opponent.unitIterator()); + map.buildPossibleTargets(selectedPawn, ctrl.opponent.unitIterator()); map.showPossibleTargets(true); - if (to.x != -1) { + if (to != null) { // quick fire -> replay touchUp - upHex.set(to); + upHex = to; touchUp(); } map.selectHex(from, true); @@ -36,7 +34,7 @@ public class StateAttack extends StateCommon map.showAttackAssists(false); map.showPossibleTargets(false); map.selectHex(from, false); - if (to.x != -1) + if (to != null) map.selectHex(to, false); } @@ -51,16 +49,16 @@ public class StateAttack extends StateCommon // activePawn is the target if ((activePawn == null) && map.isInPossibleTargets(upHex)) { map.showPossibleTargets(false); - to.set(upHex); - activePawn = map.getTopPawnAt(to); + to = upHex; + activePawn = to.getTopPawn(); map.showTarget(to, true); - map.buildAttackAssists(selectedPawn, activePawn, to, ctrl.player.unitIterator()); + map.buildAttackAssists(selectedPawn, activePawn, ctrl.player.unitIterator()); map.showAttackAssists(true); ctrl.hud.show(false, false, false, true, true, ctrl.cfg.canCancel); } if ((activePawn != null) && map.isInPossibleAttackAssists(upHex)) { - if (map.toggleAttackAssist(map.getTopPawnAt(upHex))) { + if (map.toggleAttackAssist(upHex.getTopPawn())) { map.showAssist(upHex, false); map.showTarget(upHex, true); } else { @@ -82,8 +80,8 @@ public class StateAttack extends StateCommon { int d1 = ctrl.player.d6(); int d2 = ctrl.player.d6(); - System.err.print(" attack (" + from.x + ";" + from.y + ") -> (" + to.x + ";" + to.y + ") : 2D6 -> (" + d1 + " + " + d2 + ")"); - if (map.attackPawn(selectedPawn, activePawn, from, to, d1 + d2)) + System.err.print(" attack (" + from.getCol() + ";" + from.getRow() + ") -> (" + to.getCol() + ";" + to.getRow() + ") : 2D6 -> (" + d1 + " + " + d2 + ")"); + if (map.attackPawn(selectedPawn, activePawn, d1 + d2)) ctrl.player.casualty(activePawn); map.showTarget(to, false); ctrl.setState(StateType.ANIMATION); diff --git a/core/src/ch/asynk/tankontank/game/states/StateCommon.java b/core/src/ch/asynk/tankontank/game/states/StateCommon.java index 5c73ee6..80b650f 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateCommon.java +++ b/core/src/ch/asynk/tankontank/game/states/StateCommon.java @@ -1,9 +1,8 @@ package ch.asynk.tankontank.game.states; -import com.badlogic.gdx.math.GridPoint2; - import ch.asynk.tankontank.engine.Pawn; import ch.asynk.tankontank.game.Map; +import ch.asynk.tankontank.game.Hex; import ch.asynk.tankontank.game.Ctrl; import ch.asynk.tankontank.game.State; import ch.asynk.tankontank.game.State.StateType; @@ -12,16 +11,16 @@ public abstract class StateCommon implements State { protected static Ctrl ctrl; protected static Map map; - protected static Pawn activePawn; - protected static Pawn selectedPawn; - protected static GridPoint2 selectedHex = new GridPoint2(-1, -1); - protected static GridPoint2 downHex = new GridPoint2(-1, -1); - protected static GridPoint2 upHex = new GridPoint2(-1, -1); - protected static GridPoint2 from = new GridPoint2(-1, -1); - protected static GridPoint2 to = new GridPoint2(-1, -1); + protected static Hex selectedHex = null; + protected static Hex downHex = null; + protected static Hex upHex = null; + protected static Hex from = null; + protected static Hex to = null; protected boolean isEnemy; + protected static Pawn activePawn; + protected static Pawn selectedPawn; protected static StateType nextState = StateType.SELECT; @@ -61,9 +60,9 @@ public abstract class StateCommon implements State public void clearAll() { - from.set(-1, -1); - to.set(-1, -1); - selectedHex.set(-1, -1); + from = null; + to = null; + selectedHex = null; selectedPawn = null; activePawn = null; } @@ -76,22 +75,20 @@ public abstract class StateCommon implements State ctrl.setState(next, (next == StateType.SELECT)); } - protected static boolean hexInMap(GridPoint2 hex) - { - if (hex.x == -1) return false; - return !map.isOffMap(hex); - } - public boolean downInMap(float x, float y) { - map.getHexAt(downHex, x, y); - return hexInMap(downHex); + // FIXME + downHex = (Hex) map.getTileAt(x, y); + if (downHex == null) return false; + return !downHex.isOffMap(); } public boolean upInMap(float x, float y) { - map.getHexAt(upHex, x, y); - return hexInMap(upHex); + // FIXME + upHex = (Hex) map.getTileAt(x, y); + if (upHex == null) return false; + return !upHex.isOffMap(); } protected boolean hasPawn() @@ -99,21 +96,16 @@ public abstract class StateCommon implements State return (selectedPawn != null); } - protected boolean sameHexes(GridPoint2 a, GridPoint2 b) - { - return ((a.x == b.x) && (a.y == b.y)); - } - - protected void selectHexAndPawn(GridPoint2 point) + protected void selectHexAndPawn(Hex hex) { - selectedHex.set(point); - selectedPawn = map.getTopPawnAt(selectedHex); + selectedHex = hex; + selectedPawn = selectedHex.getTopPawn(); map.selectHex(selectedHex, true); if (selectedPawn != null) isEnemy = ctrl.player.isEnemy(selectedPawn); else isEnemy = false; - System.err.println(" select " + map.getHexSafe(selectedHex.x, selectedHex.y) + selectedPawn + (isEnemy ? " enemy " : " friend ")); + System.err.println(" select " + selectedHex + selectedPawn + (isEnemy ? " enemy " : " friend ")); } protected void showPossibleTargetsMovesAssists(Pawn pawn) diff --git a/core/src/ch/asynk/tankontank/game/states/StateMove.java b/core/src/ch/asynk/tankontank/game/states/StateMove.java index 6e21f29..87d80ba 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateMove.java +++ b/core/src/ch/asynk/tankontank/game/states/StateMove.java @@ -1,7 +1,6 @@ package ch.asynk.tankontank.game.states; -import com.badlogic.gdx.math.GridPoint2; - +import ch.asynk.tankontank.game.Hex; import ch.asynk.tankontank.game.State.StateType; public class StateMove extends StateCommon @@ -15,21 +14,21 @@ public class StateMove extends StateCommon if (fromSelect) { // use selectedHex and selectedPawn - from.set(selectedHex); + from = selectedHex; activePawn = selectedPawn; - map.buildAndShowMovesAndAssits(activePawn, from); - if (to.x != -1) { + map.buildAndShowMovesAndAssits(activePawn); + if (to != null) { // quick move -> replay touchUp - upHex.set(to); + upHex = to; touchUp(); } } else { // back from rotation -> use the above and unmodified activePawn if ((activePawn == selectedPawn) || !selectedPawn.canMove()) { - upHex.set(map.getFirstMoveAssist()); - activePawn = map.getTopPawnAt(upHex); + upHex = map.getFirstMoveAssist(); + activePawn = upHex.getTopPawn(); } else { - upHex.set(selectedHex); + upHex = selectedHex; } changePawn(upHex); } @@ -41,14 +40,14 @@ public class StateMove extends StateCommon // hide all but assists : want them when in rotation map.showPossibleMoves(false); map.selectHex(from, false); - if (to.x != -1) { + if (to != null) { map.selectHex(to, false); map.showFinalPath(to, false); } if (nextState != StateType.SELECT) { - if (to.x == -1 ) - to.set(from); + if (to == null) + to = from; } } @@ -62,8 +61,8 @@ public class StateMove extends StateCommon { int s = map.possiblePathsSize(); - if (map.isInPossibleMoveAssists(upHex) || (selectedPawn.canMove() && sameHexes(selectedHex, upHex))) { - if(!sameHexes(upHex, from)) + if (map.isInPossibleMoveAssists(upHex) || (selectedPawn.canMove() && (selectedHex == upHex))) { + if(upHex != from) changePawn(upHex); } else if ((s == 0) && map.isInPossibleMoves(upHex)) { s = buildPaths(); @@ -73,8 +72,8 @@ public class StateMove extends StateCommon if (s == 1) { // prevent changePawn - if (sameHexes(from, selectedHex)) - selectedHex.set(to); + if (from == selectedHex) + selectedHex = to; ctrl.setState(StateType.ROTATE, false); } } @@ -103,26 +102,26 @@ public class StateMove extends StateCommon map.showMoveAssists(false); } - private void changePawn(GridPoint2 next) + private void changePawn(Hex next) { - if (from.x != -1) { + if (from != null) { // toggle selected to assist map.selectHex(from, false); map.showAssist(from, true); } - from.set(next); - activePawn = map.getTopPawnAt(from); + from = next; + activePawn = from.getTopPawn(); map.selectHex(from, true); map.showAssist(from, false); map.showPossibleMoves(false); - map.buildPossibleMoves(activePawn, from); + map.buildPossibleMoves(activePawn); map.showPossibleMoves(true); } private int buildPaths() { - to.set(upHex.x, upHex.y); - int s = map.buildPossiblePaths(activePawn, from, to); + to = upHex; + int s = map.buildPossiblePaths(activePawn, to); map.selectHex(to, true); map.showPossibleMoves(false); map.showPossiblePaths(true, true); @@ -131,9 +130,9 @@ public class StateMove extends StateCommon private int togglePoint(int s) { - if (sameHexes(downHex, from)) { + if (downHex == from) { // - } else if (sameHexes(downHex, to)) { + } else if (downHex == to) { // } else { map.showPossiblePaths(false, true); diff --git a/core/src/ch/asynk/tankontank/game/states/StateRotate.java b/core/src/ch/asynk/tankontank/game/states/StateRotate.java index 37958ad..e127bda 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateRotate.java +++ b/core/src/ch/asynk/tankontank/game/states/StateRotate.java @@ -18,12 +18,12 @@ public class StateRotate extends StateCommon ctrl.hud.rotateBtn.setOn(); if (rotateOnly) { - if (from.x == -1) { - // rotateBtn from Select state - from.set(selectedHex); + if (from == null) { + // rotateBtn from Select state + from = selectedHex; activePawn = selectedPawn; } - to.set(from); + to = from; } else { // show final path map.selectHex(to, true); @@ -57,7 +57,7 @@ public class StateRotate extends StateCommon if (rotationSet) return; // FIXME: if to is on the border of the board ... - o = Orientation.fromAdj(to.x, to.y, downHex.x, downHex.y); + o = Orientation.fromAdj(to.getCol(), to.getRow(), downHex.getCol(), downHex.getRow()); if (o == Orientation.KEEP) return; rotationSet = true; @@ -103,12 +103,12 @@ public class StateRotate extends StateCommon if (rotateOnly) { ctrl.setAnimationCount(1); - if (map.rotatePawn(activePawn, from, o) > 0) + if (map.rotatePawn(activePawn, o) > 0) setNextState(StateType.MOVE); ctrl.setState(StateType.ANIMATION); } else { ctrl.setAnimationCount(1); - if (map.movePawn(activePawn, from, o) > 0) + if (map.movePawn(activePawn, o) > 0) setNextState(StateType.MOVE); ctrl.setState(StateType.ANIMATION); } diff --git a/core/src/ch/asynk/tankontank/game/states/StateSelect.java b/core/src/ch/asynk/tankontank/game/states/StateSelect.java index 7990666..562c111 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateSelect.java +++ b/core/src/ch/asynk/tankontank/game/states/StateSelect.java @@ -27,7 +27,7 @@ public class StateSelect extends StateCommon @Override public void touchDown() { - if (selectedHex.x != -1) map.selectHex(selectedHex, false); + if (selectedHex != null) map.selectHex(selectedHex, false); } @Override @@ -36,13 +36,13 @@ public class StateSelect extends StateCommon if (!isEnemy) { if (map.isInPossibleMoves(upHex)) { // quick move - to.set(upHex); + to = upHex; ctrl.setState(StateType.MOVE); return; } if (map.isInPossibleTargets(upHex)) { // quick fire - to.set(upHex); + to = upHex; ctrl.setState(StateType.ATTACK); return; } @@ -52,13 +52,13 @@ public class StateSelect extends StateCommon map.hidePossibleTargetsMovesAssists(); if (hasPawn() && (!isEnemy || ctrl.cfg.showEnemyPossibilities)) { - int moves = map.buildPossibleMoves(selectedPawn, selectedHex); + int moves = map.buildPossibleMoves(selectedPawn); int targets = 0; if (isEnemy) - targets = map.buildPossibleTargets(selectedPawn, selectedHex, ctrl.player.unitIterator()); + targets = map.buildPossibleTargets(selectedPawn, ctrl.player.unitIterator()); else - targets = map.buildPossibleTargets(selectedPawn, selectedHex, ctrl.opponent.unitIterator()); - int assists = map.buildMoveAssists(selectedPawn, selectedHex); + targets = map.buildPossibleTargets(selectedPawn, ctrl.opponent.unitIterator()); + int assists = map.buildMoveAssists(selectedPawn); showPossibleTargetsMovesAssists(selectedPawn); ctrl.hud.show( ctrl.player.canPromote(selectedPawn), @@ -78,7 +78,7 @@ public class StateSelect extends StateCommon @Override public void abort() { - if (selectedHex.x != -1) map.selectHex(selectedHex, false); + if (selectedHex != null) map.selectHex(selectedHex, false); map.hidePossibleTargetsMovesAssists(); clearAll(); map.clearAll(); |