diff options
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 83 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/HeadedPawn.java | 6 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Orientation.java | 108 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Pawn.java | 8 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/SearchBoard.java | 28 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Tile.java | 4 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Hex.java | 5 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/MapA.java | 13 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/MapB.java | 13 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/screens/GameScreen.java | 9 |
10 files changed, 154 insertions, 123 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 9b05b9f..01839e9 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -33,87 +33,6 @@ public abstract class Board implements Disposable public Tile getNewTile(float cx, float cy); } - public enum Orientation - { - ALL(0, 63), - KEEP(0, 0), - NORTH(270, 1), - NORTH_EAST(210, 2), - SOUTH_EAST(150, 4), - SOUTH(90, 8), - SOUTH_WEST (30, 16), - NORTH_WEST(330, 32); - - public static int offset = 0; - public static float delta = 5f; - private final int r; - public final int s; - - Orientation(int r, int s) { this.r = r; this.s = s; } - - public float r() { return offset + r; } - - public boolean isInSides(int sides) - { - return ((sides & s) == s); - } - - public Orientation left() - { - if (this == NORTH) return NORTH_WEST; - else return fromSide(s >> 1); - } - - public Orientation right() - { - if (this == NORTH_WEST) return NORTH; - else return fromSide(s << 1); - } - - public Orientation opposite() - { - return left().left().left(); - } - - public int allBut() - { - return ALL.s & (s ^ 0xFFFF); - } - - public int getFrontSides() - { - return s | left().s | right().s; - } - - public int getBackSides() - { - return opposite().getFrontSides(); - } - - public static Orientation fromSide(int s) - { - if (s == 1) return NORTH; - else if (s == NORTH_EAST.s) return NORTH_EAST; - else if (s == SOUTH_EAST.s) return SOUTH_EAST; - else if (s == SOUTH.s) return SOUTH; - else if (s == SOUTH_WEST.s) return SOUTH_WEST; - else if (s == NORTH_WEST.s) return NORTH_WEST; - else return KEEP; - } - - public static Orientation fromRotation(float r) - { - if (r < 0) r += 360f; - if ((r > (NORTH.r - 5f)) && (r < (NORTH.r + 5f))) return NORTH; - else if ((r > (NORTH_EAST.r - delta)) && (r < (NORTH_EAST.r + delta))) return NORTH_EAST; - else if ((r > (SOUTH_EAST.r - delta)) && (r < (SOUTH_EAST.r + delta))) return SOUTH_EAST; - else if ((r > (SOUTH.r - delta)) && (r < (SOUTH.r + delta))) return SOUTH; - else if ((r > (SOUTH_WEST.r - delta)) && (r < (SOUTH_WEST.r + delta))) return SOUTH_WEST; - else if ((r > (NORTH_WEST.r - delta)) && (r < (NORTH_WEST.r + delta))) return NORTH_WEST; - else return KEEP; - } - } - public static class Config { public int cols; @@ -435,7 +354,7 @@ public abstract class Board implements Disposable for (int i = (nodes.size() - 2); i >= 0; i--) { SearchBoard.Node node = nodes.get(i); GridPoint3 point = gridPoint3Pool.obtain(); - point.set(node.col, node.row, getOrientation(prev, node).r); + point.set(node.col, node.row, (int) getOrientation(prev, node).r()); path.add(point); prev = node; } diff --git a/core/src/ch/asynk/tankontank/engine/HeadedPawn.java b/core/src/ch/asynk/tankontank/engine/HeadedPawn.java index affe98b..3f01c72 100644 --- a/core/src/ch/asynk/tankontank/engine/HeadedPawn.java +++ b/core/src/ch/asynk/tankontank/engine/HeadedPawn.java @@ -12,13 +12,13 @@ import com.badlogic.gdx.math.Vector3; public abstract class HeadedPawn extends Pawn { private Image head; - protected Board.Orientation orientation; + protected Orientation orientation; public HeadedPawn(TextureRegion region, TextureRegion head, TextureAtlas atlas) { super(region, atlas); this.head = new Image(head); - this.orientation = Board.Orientation.KEEP; + this.orientation = Orientation.KEEP; } @Override @@ -49,7 +49,7 @@ public abstract class HeadedPawn extends Pawn float cy = y + (getHeight() / 2f); head.centerOn(cx, cy); head.setRotation(z); - this.orientation = Board.Orientation.fromRotation(z); + this.orientation = Orientation.fromRotation(z); } @Override diff --git a/core/src/ch/asynk/tankontank/engine/Orientation.java b/core/src/ch/asynk/tankontank/engine/Orientation.java new file mode 100644 index 0000000..5b5cbbb --- /dev/null +++ b/core/src/ch/asynk/tankontank/engine/Orientation.java @@ -0,0 +1,108 @@ +package ch.asynk.tankontank.engine; + +// import java.util.Set; +// import java.util.List; +// import java.util.Vector; +// import java.util.Iterator; +// import java.util.LinkedHashSet; + +// import com.badlogic.gdx.Gdx; + +// import com.badlogic.gdx.utils.Disposable; + +// import com.badlogic.gdx.graphics.Texture; +// import com.badlogic.gdx.graphics.g2d.Batch; +// import com.badlogic.gdx.graphics.glutils.ShapeRenderer; + +// import com.badlogic.gdx.utils.Pool; +// import com.badlogic.gdx.math.Vector2; +// import com.badlogic.gdx.math.Vector3; +// import com.badlogic.gdx.math.GridPoint2; +// import com.badlogic.gdx.math.GridPoint3; +// import com.badlogic.gdx.math.Matrix4; + +// import ch.asynk.tankontank.engine.gfx.Image; +// import ch.asynk.tankontank.engine.gfx.Animation; +// import ch.asynk.tankontank.engine.gfx.animations.AnimationSequence; +// import ch.asynk.tankontank.engine.gfx.animations.RunnableAnimation; + +public enum Orientation +{ + ALL(0, 63), + KEEP(0, 0), + NORTH(270, 1), + NORTH_EAST(210, 2), + SOUTH_EAST(150, 4), + SOUTH(90, 8), + SOUTH_WEST (30, 16), + NORTH_WEST(330, 32); + + public static int offset = 0; + public static float delta = 5f; + private final int r; + public final int s; + + Orientation(int r, int s) { this.r = r; this.s = s; } + + public float r() { return offset + r; } + + public boolean isInSides(int sides) + { + return ((sides & s) == s); + } + + public Orientation left() + { + if (this == NORTH) return NORTH_WEST; + else return fromSide(s >> 1); + } + + public Orientation right() + { + if (this == NORTH_WEST) return NORTH; + else return fromSide(s << 1); + } + + public Orientation opposite() + { + return left().left().left(); + } + + public int allBut() + { + return ALL.s & (s ^ 0xFFFF); + } + + public int getFrontSides() + { + return s | left().s | right().s; + } + + public int getBackSides() + { + return opposite().getFrontSides(); + } + + public static Orientation fromSide(int s) + { + if (s == 1) return NORTH; + else if (s == NORTH_EAST.s) return NORTH_EAST; + else if (s == SOUTH_EAST.s) return SOUTH_EAST; + else if (s == SOUTH.s) return SOUTH; + else if (s == SOUTH_WEST.s) return SOUTH_WEST; + else if (s == NORTH_WEST.s) return NORTH_WEST; + else return KEEP; + } + + public static Orientation fromRotation(float r) + { + if (r < 0) r += 360f; + if ((r > (NORTH.r - 5f)) && (r < (NORTH.r + 5f))) return NORTH; + else if ((r > (NORTH_EAST.r - delta)) && (r < (NORTH_EAST.r + delta))) return NORTH_EAST; + else if ((r > (SOUTH_EAST.r - delta)) && (r < (SOUTH_EAST.r + delta))) return SOUTH_EAST; + else if ((r > (SOUTH.r - delta)) && (r < (SOUTH.r + delta))) return SOUTH; + else if ((r > (SOUTH_WEST.r - delta)) && (r < (SOUTH_WEST.r + delta))) return SOUTH_WEST; + else if ((r > (NORTH_WEST.r - delta)) && (r < (NORTH_WEST.r + delta))) return NORTH_WEST; + else return KEEP; + } +} diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java index 8c39310..9c7b4d2 100644 --- a/core/src/ch/asynk/tankontank/engine/Pawn.java +++ b/core/src/ch/asynk/tankontank/engine/Pawn.java @@ -48,9 +48,9 @@ public abstract class Pawn extends Image implements Disposable return path.getFirst(); } - public Board.Orientation getOrientation() + public Orientation getOrientation() { - return Board.Orientation.fromRotation(getRotation()); + return Orientation.fromRotation(getRotation()); } public void moveDone() @@ -60,9 +60,9 @@ public abstract class Pawn extends Image implements Disposable path.push(v); } - public void pushMove(float x, float y, Board.Orientation o) + public void pushMove(float x, float y, Orientation o) { - float r = ((o == Board.Orientation.KEEP) ? getRotation() : o.r()); + float r = ((o == Orientation.KEEP) ? getRotation() : o.r()); setPosition(x, y, r); Vector3 v = new Vector3(x, y, r); if ((path.size() == 0) || (!v.equals(path.getFirst()))) diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java index 0fd21e1..953459d 100644 --- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java +++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java @@ -28,7 +28,7 @@ public class SearchBoard private Board board; private int searchCount; private Node nodes[]; - private Board.Orientation sides[]; + private Orientation sides[]; private ArrayDeque<Node> stack; private LinkedList<Node> queue; @@ -56,13 +56,13 @@ public class SearchBoard nodes[i + (j * cols)] = new Node((i + dx), j); } - this.sides = new Board.Orientation[6]; - sides[0] = Board.Orientation.NORTH; - sides[1] = Board.Orientation.NORTH_EAST; - sides[2] = Board.Orientation.SOUTH_EAST; - sides[3] = Board.Orientation.SOUTH; - sides[4] = Board.Orientation.SOUTH_WEST; - sides[5] = Board.Orientation.NORTH_WEST; + this.sides = new Orientation[6]; + sides[0] = Orientation.NORTH; + sides[1] = Orientation.NORTH_EAST; + sides[2] = Orientation.SOUTH_EAST; + sides[3] = Orientation.SOUTH; + sides[4] = Orientation.SOUTH_WEST; + sides[5] = Orientation.NORTH_WEST; this.queue = new LinkedList<Node>(); this.stack = new ArrayDeque<Node>(20); @@ -242,32 +242,32 @@ public class SearchBoard private void adjacentTargets(Node src, int angle, Node a[]) { // move in allowed directions - if (Board.Orientation.NORTH.isInSides(angle)) + if (Orientation.NORTH.isInSides(angle)) a[0] = getNode((src.col + 1), src.row); else a[0] = null; - if (Board.Orientation.NORTH_EAST.isInSides(angle)) + if (Orientation.NORTH_EAST.isInSides(angle)) a[1] = getNode(src.col, (src.row - 1)); else a[1] = null; - if (Board.Orientation.SOUTH_EAST.isInSides(angle)) + if (Orientation.SOUTH_EAST.isInSides(angle)) a[2] = getNode((src.col - 1), (src.row - 1)); else a[2] = null; - if (Board.Orientation.SOUTH.isInSides(angle)) + if (Orientation.SOUTH.isInSides(angle)) a[3] = getNode((src.col - 1), src.row); else a[3] = null; - if (Board.Orientation.SOUTH_WEST.isInSides(angle)) + if (Orientation.SOUTH_WEST.isInSides(angle)) a[4] = getNode(src.col, (src.row + 1)); else a[4] = null; - if (Board.Orientation.NORTH_WEST.isInSides(angle)) + if (Orientation.NORTH_WEST.isInSides(angle)) a[5] = getNode((src.col + 1), (src.row + 1)); else a[5] = null; diff --git a/core/src/ch/asynk/tankontank/engine/Tile.java b/core/src/ch/asynk/tankontank/engine/Tile.java index 7e41a17..566f0cc 100644 --- a/core/src/ch/asynk/tankontank/engine/Tile.java +++ b/core/src/ch/asynk/tankontank/engine/Tile.java @@ -19,8 +19,8 @@ public abstract class Tile implements Drawable private Vector2 center; public abstract boolean atLeastOneMove(Pawn pawn); - public abstract boolean road(Board.Orientation side); - public abstract int costFrom(Pawn pawn, Board.Orientation side, boolean road); + public abstract boolean road(Orientation side); + public abstract int costFrom(Pawn pawn, Orientation side, boolean road); public abstract boolean hasTargetsFor(Pawn pawn); public abstract boolean isOffMap(); public abstract boolean blockLineOfSightFrom(Tile tile); diff --git a/core/src/ch/asynk/tankontank/game/Hex.java b/core/src/ch/asynk/tankontank/game/Hex.java index 8fb7be8..70377ac 100644 --- a/core/src/ch/asynk/tankontank/game/Hex.java +++ b/core/src/ch/asynk/tankontank/game/Hex.java @@ -7,6 +7,7 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas; import ch.asynk.tankontank.engine.Pawn; import ch.asynk.tankontank.engine.Tile; import ch.asynk.tankontank.engine.Board; +import ch.asynk.tankontank.engine.Orientation; public class Hex extends Tile { @@ -65,13 +66,13 @@ public class Hex extends Tile } @Override - public boolean road(Board.Orientation side) + public boolean road(Orientation side) { return (side.s == (roads & side.s)); } @Override - public int costFrom(Pawn pawn, Board.Orientation side, boolean road) + public int costFrom(Pawn pawn, Orientation side, boolean road) { if (hasUnits()) return Integer.MAX_VALUE; if (road) return 1; diff --git a/core/src/ch/asynk/tankontank/game/MapA.java b/core/src/ch/asynk/tankontank/game/MapA.java index f190b4b..686efed 100644 --- a/core/src/ch/asynk/tankontank/game/MapA.java +++ b/core/src/ch/asynk/tankontank/game/MapA.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import ch.asynk.tankontank.engine.Board; +import ch.asynk.tankontank.engine.Orientation; public class MapA extends Map { @@ -40,12 +41,12 @@ public class MapA extends Map getHex(12, 5).terrain = Hex.Terrain.OFFMAP; getHex(13, 7).terrain = Hex.Terrain.OFFMAP; - int N = Map.Orientation.NORTH.s; - int S = Map.Orientation.SOUTH.s; - int NE = Map.Orientation.NORTH_EAST.s; - int NW = Map.Orientation.NORTH_WEST.s; - int SE = Map.Orientation.SOUTH_EAST.s; - int SW = Map.Orientation.SOUTH_WEST.s; + int N = Orientation.NORTH.s; + int S = Orientation.SOUTH.s; + int NE = Orientation.NORTH_EAST.s; + int NW = Orientation.NORTH_WEST.s; + int SE = Orientation.SOUTH_EAST.s; + int SW = Orientation.SOUTH_WEST.s; getHex(6, 1).roads = (NW | SW); for (int i = 1; i < 11; i++) { diff --git a/core/src/ch/asynk/tankontank/game/MapB.java b/core/src/ch/asynk/tankontank/game/MapB.java index cdce945..35416a9 100644 --- a/core/src/ch/asynk/tankontank/game/MapB.java +++ b/core/src/ch/asynk/tankontank/game/MapB.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import ch.asynk.tankontank.engine.Board; +import ch.asynk.tankontank.engine.Orientation; public class MapB extends Map { @@ -40,12 +41,12 @@ public class MapB extends Map getHex(12, 5).terrain = Hex.Terrain.OFFMAP; getHex(13, 7).terrain = Hex.Terrain.OFFMAP; - int N = Map.Orientation.NORTH.s; - int S = Map.Orientation.SOUTH.s; - int NE = Map.Orientation.NORTH_EAST.s; - int NW = Map.Orientation.NORTH_WEST.s; - int SE = Map.Orientation.SOUTH_EAST.s; - int SW = Map.Orientation.SOUTH_WEST.s; + int N = Orientation.NORTH.s; + int S = Orientation.SOUTH.s; + int NE = Orientation.NORTH_EAST.s; + int NW = Orientation.NORTH_WEST.s; + int SE = Orientation.SOUTH_EAST.s; + int SW = Orientation.SOUTH_WEST.s; getHex(1, 2).roads = (S | NW); getHex(2, 3).roads = (SE | N); diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java index 73734ca..2b04ea2 100644 --- a/core/src/ch/asynk/tankontank/screens/GameScreen.java +++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java @@ -32,8 +32,9 @@ import ch.asynk.tankontank.game.GameCtrl; import ch.asynk.tankontank.game.GameFactory; import ch.asynk.tankontank.game.GameFactory.UnitType; // TEST -import ch.asynk.tankontank.engine.Board; import ch.asynk.tankontank.engine.Pawn; +import ch.asynk.tankontank.engine.Board; +import ch.asynk.tankontank.engine.Orientation; public class GameScreen implements Screen { @@ -90,7 +91,7 @@ public class GameScreen implements Screen debugShapes = new ShapeRenderer(); // TEST - Board.Orientation o = Board.Orientation.NORTH; + Orientation o = Orientation.NORTH; addUnit(4, 7, o, UnitType.GE_AT_GUN); addUnit(3, 6, o, UnitType.GE_INFANTRY); addUnit(3, 5, o, UnitType.GE_KINGTIGER); @@ -99,7 +100,7 @@ public class GameScreen implements Screen addUnit(1, 2, o, UnitType.GE_TIGER); addUnit(1, 1, o, UnitType.GE_WESPE); - o = Board.Orientation.SOUTH; + o = Orientation.SOUTH; addUnit(12, 7, o, UnitType.US_AT_GUN); addUnit(11, 6, o, UnitType.US_INFANTRY); addUnit(11, 5, o, UnitType.US_PERSHING); @@ -113,7 +114,7 @@ public class GameScreen implements Screen Gdx.input.setInputProcessor(getMultiplexer()); } - private void addUnit(int col, int row, Board.Orientation o, UnitType t) + private void addUnit(int col, int row, Orientation o, UnitType t) { Pawn p = factory.getUnit(t); map.setPawnAt(p, col, row, o); |