summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/gdx/boardgame/Orientation.java
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-10-10 06:44:07 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2018-10-10 06:44:07 +0200
commitf5c6b7a9b4cc6be2db93ff1f274216b90116fec6 (patch)
treecd04bc836250284ad94824d10b516c6a878d44ec /core/src/ch/asynk/gdx/boardgame/Orientation.java
parent909d7771fa7a5e65bc7b11b8674a147620f3350d (diff)
downloadgdx-boardgame-f5c6b7a9b4cc6be2db93ff1f274216b90116fec6.zip
gdx-boardgame-f5c6b7a9b4cc6be2db93ff1f274216b90116fec6.tar.gz
add Orientation
Diffstat (limited to 'core/src/ch/asynk/gdx/boardgame/Orientation.java')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/Orientation.java90
1 files changed, 90 insertions, 0 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/Orientation.java b/core/src/ch/asynk/gdx/boardgame/Orientation.java
new file mode 100644
index 0000000..98d1eda
--- /dev/null
+++ b/core/src/ch/asynk/gdx/boardgame/Orientation.java
@@ -0,0 +1,90 @@
+package ch.asynk.gdx.boardgame;
+
+public enum Orientation
+{
+ ALL(255, 0),
+ KEEP( 0, 0),
+ DEFAULT(0, -1),
+ N( 1, -1),
+ NW( 2, -1),
+ W( 4, -1),
+ SW( 8, -1),
+ S( 16, -1),
+ SE( 32, -1),
+ E( 64, -1),
+ NE(128, -1);
+ private int s;
+ private int r;
+ Orientation(int s, int r)
+ {
+ this.s = s;
+ this.r = r;
+ }
+ public int s() { return s; }
+ public int r() { return r; }
+
+ private static float delta = 5f;
+
+ public static void setValues(int [] angles)
+ {
+ DEFAULT.r = angles[0];
+ N.r = angles[1];
+ NW.r = angles[2];
+ W.r = angles[3];
+ SW.r = angles[4];
+ S.r = angles[5];
+ SE.r = angles[6];
+ E.r = angles[7];
+ NE.r = angles[8];
+ }
+
+ public int allBut()
+ {
+ return ALL.s & (s ^ 0xFFFF);
+ }
+
+ public boolean belongsTo(int sides)
+ {
+ return ((sides & s) == s);
+ }
+
+ public Orientation left()
+ {
+ Orientation o = (this == NE) ? N : fromS(this.s << 1);
+ return (o.r == -1) ? o.left() : o;
+ }
+
+ public Orientation right()
+ {
+ Orientation o = (this == N) ? NE : fromS(this.s >> 1);
+ return (o.r == -1) ? o.right() : o;
+ }
+
+ public static Orientation fromS(int s)
+ {
+ if (s == N.s) return N;
+ else if (s == NW.s) return NW;
+ else if (s == W.s) return W;
+ else if (s == SW.s) return SW;
+ else if (s == S.s) return S;
+ else if (s == SE.s) return SE;
+ else if (s == E.s) return E;
+ else if (s == NE.s) return NE;
+ else return KEEP;
+ }
+
+ public static Orientation fromR(float r)
+ {
+ if (r < 0) r += 360f;
+ if ((r > (N.r - delta)) && (r < (N.r + delta))) return N;
+ else if ((r > (NW.r - delta)) && (r < (NW.r + delta))) return NW;
+ else if ((r > (W.r - delta)) && (r < (W.r + delta))) return W;
+ else if ((r > (SW.r - delta)) && (r < (SW.r + delta))) return SW;
+ else if ((r > (S.r - delta)) && (r < (S.r + delta))) return S;
+ else if ((r > (SE.r - delta)) && (r < (SE.r + delta))) return SE;
+ else if ((r > (E.r - delta)) && (r < (E.r + delta))) return E;
+ else if ((r > (NE.r - delta)) && (r < (NE.r + delta))) return NE;
+ else return KEEP;
+
+ }
+}