summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-10-14 08:29:24 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2018-10-14 08:29:24 +0200
commit94e780a885330797664a09b3a32f4cd809b2395a (patch)
tree621a3829543998428eb118916c8746b47b6e2542 /core/src/ch
parent4d8559eb03abfd918e12c124f1c56df39bd134cb (diff)
downloadgdx-boardgame-94e780a885330797664a09b3a32f4cd809b2395a.zip
gdx-boardgame-94e780a885330797664a09b3a32f4cd809b2395a.tar.gz
Orientation : normalize 0° is facing East
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/Orientation.java56
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java5
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java3
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java5
4 files changed, 36 insertions, 33 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/Orientation.java b/core/src/ch/asynk/gdx/boardgame/Orientation.java
index 98d1eda..835afe4 100644
--- a/core/src/ch/asynk/gdx/boardgame/Orientation.java
+++ b/core/src/ch/asynk/gdx/boardgame/Orientation.java
@@ -5,14 +5,14 @@ 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);
+ E( 1, -1),
+ NE( 2, -1),
+ N( 4, -1),
+ NW( 8, -1),
+ W( 16, -1),
+ SW( 32, -1),
+ S( 64, -1),
+ SE(128, -1);
private int s;
private int r;
Orientation(int s, int r)
@@ -28,14 +28,14 @@ public enum Orientation
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];
+ E.r = angles[1];
+ NE.r = angles[2];
+ N.r = angles[3];
+ NW.r = angles[4];
+ W.r = angles[5];
+ SW.r = angles[6];
+ S.r = angles[7];
+ SE.r = angles[8];
}
public int allBut()
@@ -50,40 +50,40 @@ public enum Orientation
public Orientation left()
{
- Orientation o = (this == NE) ? N : fromS(this.s << 1);
+ Orientation o = (this == SE) ? E : fromS(this.s << 1);
return (o.r == -1) ? o.left() : o;
}
public Orientation right()
{
- Orientation o = (this == N) ? NE : fromS(this.s >> 1);
+ Orientation o = (this == E) ? SE : fromS(this.s >> 1);
return (o.r == -1) ? o.right() : o;
}
public static Orientation fromS(int s)
{
- if (s == N.s) return N;
+ if (s == E.s) return E;
+ else if (s == NE.s) return NE;
+ else if (s == N.s) return N;
else if (s == NW.s) return NW;
- else if (s == W.s) return W;
+ else if (s == W.s) return W;
else if (s == SW.s) return SW;
- else if (s == S.s) return S;
+ 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;
+ if ((r > ( E.r - delta)) && (r < ( E.r + delta))) return E;
+ else if ((r > (NE.r - delta)) && (r < (NE.r + delta))) return NE;
+ else 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 > ( 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 > ( 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;
}
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
index 30aef0b..c78fb77 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
@@ -33,8 +33,9 @@ public class HexBoard implements Board
// rows are vertical°
// bottom left is the left vertice of the most bottom-left horizontal hex side of the map
- private static final int [] vAngles = {330, -1, 30, 90, 150, -1, 210, 270, 330};
- private static final int [] hAngles = { 0, 0, 60, -1, 120, 180, 240, -1, 300};
+ // [0] is 0° facing East
+ private static final int [] vAngles = {60, 0, 60, -1, 120, 180, 240, -1, 300};
+ private static final int [] hAngles = {90, -1, 30, 90, 150, -1, 210, 270, 330};
public HexBoard(float side, float x0, float y0, BoardFactory.BoardOrientation boardOrientation)
{
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
index bfe23a7..665d1ca 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
@@ -8,7 +8,8 @@ public class SquareBoard implements Board
private final float x0; // bottom left x offset
private final float y0; // bottom left y offset
- private static final int [] angles = { 0, 0, -1, 90, -1, 180, -1, 270, -1};
+ // [0] is 0° facing East
+ private static final int [] angles = {90, 0, -1, 90, -1, 180, -1, 270, -1, 0};
public SquareBoard(float side, float x0, float y0)
{
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
index f49550d..1fbd034 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
@@ -16,8 +16,9 @@ public class TriangleBoard implements Board
private final float h23; // 2/3 height of the triangle
private final float h43; // 4/3 height of the triangle
- private static final int [] vAngles = {330, -1, 30, 90, 150, -1, 210, 270, 330};
- private static final int [] hAngles = { 0, 0, 60, -1, 120, 180, 240, -1, 300};
+ // [0] is 0° facing East
+ private static final int [] vAngles = {60, 0, 60, -1, 120, 180, 240, -1, 300};
+ private static final int [] hAngles = {30, -1, 30, 90, 150, -1, 210, 270, 330};
public TriangleBoard(float side, float x0, float y0, BoardFactory.BoardOrientation boardOrientation)
{