summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/zproject/engine/board
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-09-14 09:13:20 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2018-09-14 09:13:20 +0200
commit76c4a8eccdc276583c215e5ad09b5fb2f07ac53e (patch)
tree8e026033a22f2b4d3dfe02235ab40d897309321e /core/src/ch/asynk/zproject/engine/board
parenta3cc66dc1fe2f468b234083baacd82a37c51fd3f (diff)
downloadgdx-boardgame-76c4a8eccdc276583c215e5ad09b5fb2f07ac53e.zip
gdx-boardgame-76c4a8eccdc276583c215e5ad09b5fb2f07ac53e.tar.gz
ch/asynk/zproject/engine -> ch/asynk/gdx/board
Diffstat (limited to 'core/src/ch/asynk/zproject/engine/board')
-rw-r--r--core/src/ch/asynk/zproject/engine/board/BoardFactory.java40
-rw-r--r--core/src/ch/asynk/zproject/engine/board/HexBoard.java144
-rw-r--r--core/src/ch/asynk/zproject/engine/board/SquareBoard.java35
3 files changed, 0 insertions, 219 deletions
diff --git a/core/src/ch/asynk/zproject/engine/board/BoardFactory.java b/core/src/ch/asynk/zproject/engine/board/BoardFactory.java
deleted file mode 100644
index 7c472b9..0000000
--- a/core/src/ch/asynk/zproject/engine/board/BoardFactory.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package ch.asynk.gdx.board.engine.board;
-
-import ch.asynk.gdx.board.engine.Board;
-
-public class BoardFactory
-{
- public enum BoardType
- {
- HEX, SQUARE,
- }
-
- public enum BoardOrientation
- {
- VERTICAL,
- HORIZONTAL,
- }
-
- public static Board getBoard(BoardType boardType, float side)
- {
- return getBoard(boardType, side, 0f, 0f, BoardOrientation.VERTICAL);
- }
-
- public static Board getBoard(BoardType boardType, float side, float x0, float y0)
- {
- return getBoard(boardType, side, x0, y0, BoardOrientation.VERTICAL);
- }
-
- public static Board getBoard(BoardType boardType, float side, float x0, float y0, BoardOrientation boardOrientation)
- {
- switch(boardType)
- {
- case HEX:
- return new HexBoard(side, x0, y0, boardOrientation);
- case SQUARE:
- return new SquareBoard(side, x0, y0);
- default:
- throw new RuntimeException( String.format("%s board type is not implemented yet.", boardType) );
- }
- }
-}
diff --git a/core/src/ch/asynk/zproject/engine/board/HexBoard.java b/core/src/ch/asynk/zproject/engine/board/HexBoard.java
deleted file mode 100644
index d639e0c..0000000
--- a/core/src/ch/asynk/zproject/engine/board/HexBoard.java
+++ /dev/null
@@ -1,144 +0,0 @@
-package ch.asynk.gdx.board.engine.board;
-
-import com.badlogic.gdx.math.Vector2;
-
-import ch.asynk.gdx.board.engine.Board;
-
-public class HexBoard implements Board
-{
- private float side; // length of the side of the hex
- private float x0; // bottom left x offset
- private float y0; // bottom left y offset
- private BoardFactory.BoardOrientation orientation;
-
- private float w; // side to side orthogonal distance
- private float dw; // half hex : w/2
- private float dh; // hex top : s/2
- private float h; // square height : s + dh
- private float slope; // dh / dw
-
- // BoardOrientation.VERTICAL : 2 vertical sides : 2 vertices pointing up and down
- // coordinates
- // \
- // \___
- // cols are horizontal
- // rows are at -120°
- // bottom left is the bottom vertice of the most bottom-left vertical hex side of the map
- //
- // BoardOrientation.HORIZONTAL : 2 horizontal sides : 2 vertices pointing left and right
- // coordinates
- // |
- // |
- // \
- // \
- // cols are at +120°
- // rows are vertical°
- // bottom left is the left vertice of the most bottom-left horizontal hex side of the map
-
- public HexBoard(float side, float x0, float y0, BoardFactory.BoardOrientation boardOrientation)
- {
- this.side = side;
- this.x0 = x0;
- this.y0 = y0;
- this.orientation = boardOrientation;
-
- this.w = side * 1.73205f;
- this.dw = w / 2.0f;
- this.dh = side / 2.0f;
- this.h = side + dh;
- this.slope = dh / dw;
- }
-
- @Override public void centerOf(int x, int y, Vector2 v)
- {
- float cx = this.x0;
- float cy = this.y0;
-
- if (this.orientation == BoardFactory.BoardOrientation.VERTICAL) {
- cx += (this.dw + (x * this.w) - (y * this.dw));
- cy += (this.dh + (y * this.h));
- } else {
- cx += (this.dh + (x * this.h));
- cy += (this.dw + (y * this.w) - (x * this.dw));
- }
-
- v.set(cx, cy);
- }
-
- @Override public void toBoard(float x, float y, Vector2 v)
- {
- int col = -1;
- int row = -1;
-
- if (this.orientation == BoardFactory.BoardOrientation.VERTICAL) {
- // compute row
- float dy = y - this.y0;
- row = (int) (dy / this.h);
- if (dy < 0.f) {
- row -= 1;
- }
-
- // compute col
- float dx = x - this.x0 + (row * this.dw);
- col = (int) (dx / this.w);
- if (dx < 0f) {
- col -= 1;
- }
-
- // upper rectangle or hex body
- if (dy > ((row * this.h) + this.side)) {
- dy -= ((row * this.h) + this.side);
- dx -= (col * this.w);
- // upper left or right rectangle
- if (dx < this.dw) {
- if (dy > (dx * this.slope)) {
- // upper left hex
- row += 1;
- }
- } else {
- // if (dy > ((2 * this.dh) - (dx * this.slope))) {
- if (dy > ((this.w - dx) * this.slope)) {
- // upper right hex
- row += 1;
- col += 1;
- }
- }
- }
- } else {
- // compute col
- float dx = x - this.x0;
- col = (int) (dx / this.h);
- if (dx < 0.f) {
- col -= 1;
- }
-
- // compute row
- float dy = y - this.y0 + (col * this.dw);
- row = (int) (dy / this.w);
- if (dy < 0f) {
- row -= 1;
- }
-
- // right rectangle or hex body
- if (dx > ((col * this.h) + this.side)) {
- dx -= ((col * this.h) + this.side);
- dy -= (row * this.w);
- // upper or lower rectangle
- if (dy > ((this.dw - dx) / this.slope)) {
- if (dy > ((2 * this.dw) - (dx / this.slope))) {
- // upper right hex
- col += 1;
- row += 1;
- }
- } else {
- if (dy < (dx / this.slope)) {
- // lower right hex
- col += 1;
- }
- }
- }
- }
-
- v.set(col, row);
- }
-}
diff --git a/core/src/ch/asynk/zproject/engine/board/SquareBoard.java b/core/src/ch/asynk/zproject/engine/board/SquareBoard.java
deleted file mode 100644
index 824084f..0000000
--- a/core/src/ch/asynk/zproject/engine/board/SquareBoard.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package ch.asynk.gdx.board.engine.board;
-
-import com.badlogic.gdx.math.Vector2;
-
-import ch.asynk.gdx.board.engine.Board;
-
-public class SquareBoard implements Board
-{
- private float side; // length of the side of a square
- private float x0; // bottom left x offset
- private float y0; // bottom left y offset
-
- public SquareBoard(float side, float x0, float y0)
- {
- this.side = side;
- this.x0 = x0;
- this.y0 = y0;
- }
-
- @Override public void centerOf(int x, int y, Vector2 v)
- {
- float cx = this.x0 + (this.side / 2) + (this.side * x);
- float cy = this.y0 + (this.side / 2) + (this.side * y);
-
- v.set(cx, cy);
- }
-
- @Override public void toBoard(float x, float y, Vector2 v)
- {
- int col = (int) ((x - this.x0) / this.side);
- int row = (int) ((y - this.y0) / this.side);
-
- v.set(col, row);
- }
-}