diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2018-09-20 16:41:36 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2018-09-20 16:41:36 +0200 |
commit | 7c2bbdb9ae7f10a87c6a63d6435712b8751eb6fd (patch) | |
tree | dc6fee885c5a6e914d02b748aa17473294e6eb99 /core | |
parent | 57cddbf4b79b6c342e53acfa804d01f94d9bd266 (diff) | |
download | gdx-boardgame-7c2bbdb9ae7f10a87c6a63d6435712b8751eb6fd.zip gdx-boardgame-7c2bbdb9ae7f10a87c6a63d6435712b8751eb6fd.tar.gz |
TriangleBoard : fix centerOf(…)
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/gdx/tabletop/board/TriangleBoard.java | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/core/src/ch/asynk/gdx/tabletop/board/TriangleBoard.java b/core/src/ch/asynk/gdx/tabletop/board/TriangleBoard.java index 961f552..94f93e4 100644 --- a/core/src/ch/asynk/gdx/tabletop/board/TriangleBoard.java +++ b/core/src/ch/asynk/gdx/tabletop/board/TriangleBoard.java @@ -14,6 +14,9 @@ public class TriangleBoard implements Board private final float d; // side / 2 private final float h; // height of the triangle private final float m; // h / d + private final float h13; // 1/3 height of the triangle + private final float h23; // 2/3 height of the triangle + private final float h43; // 4/3 height of the triangle public TriangleBoard(float side, float x0, float y0, BoardFactory.BoardOrientation boardOrientation) { @@ -25,6 +28,9 @@ public class TriangleBoard implements Board this.d = side / 2f; this.h = side * 0.866f; this.m = this.h / this.d; + this.h13 = this.h * 0.33333f; + this.h23 = this.h * 0.66666f; + this.h43 = this.h * 1.33333f; } @Override public void centerOf(int x, int y, Vector2 v) @@ -34,10 +40,10 @@ public class TriangleBoard implements Board if (this.orientation == BoardFactory.BoardOrientation.VERTICAL) { cy += (y * this.d); - cx += ((this.h * ( (y % 2 == 0) ? 0.33333f : 0.66666f )) + (x * this.h)); + cx += ((x * this.h) + (((x + y) % 2 == 0) ? this.h23 : this.h13)); } else { cx += (this.d + (x * this.d)); - cy += ((this.h * ( (x % 2 == 0) ? 0.33333f : 0.66666f )) + (y * this.h)); + cy += ((y * this.h) + (((x + y) % 2 == 0) ? this.h13 : this.h23)); } v.set(cx, cy); |