summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-25 11:14:05 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-25 11:14:05 +0200
commit7a1a3025b664c861016e8178331ce246aed08e8a (patch)
tree99c49781a1aed979bdd7d491ca06d853a12c1598 /core
parent035009b625f45b0e8a499ceaa93b80a1bf69702d (diff)
downloadRustAndDust-7a1a3025b664c861016e8178331ce246aed08e8a.zip
RustAndDust-7a1a3025b664c861016e8178331ce246aed08e8a.tar.gz
Board.Orientation: getBackSides(), oppositeSide(), left(), right()
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java57
1 files changed, 54 insertions, 3 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index 20bf494..6236478 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -29,20 +29,71 @@ public abstract class Board extends Image implements Disposable
public enum Orientation
{
KEEP(0, 0),
- NORTH(-90, 1),
- NORTH_EAST(-150, 2),
+ NORTH(270, 1),
+ NORTH_EAST(210, 2),
SOUTH_EAST(150, 4),
SOUTH(90, 8),
SOUTH_WEST (30, 16),
- NORTH_WEST(-30, 32);
+ 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 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 oppositeSide()
+ {
+ return left().left().left();
+ }
+
+ public int getFrontSides()
+ {
+ return s | left().s | right().s;
+ }
+
+ public int getBackSides()
+ {
+ return oppositeSide().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