diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2018-09-14 15:31:41 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2018-09-14 15:31:41 +0200 |
commit | b35b61953623857f911255a88a6f2268076ee8ad (patch) | |
tree | 292c031da0145710a4a3a8634732a0c6ed106037 | |
parent | c075340985d0a5b815cdfde847f32b418078d501 (diff) | |
download | gdx-boardgame-b35b61953623857f911255a88a6f2268076ee8ad.zip gdx-boardgame-b35b61953623857f911255a88a6f2268076ee8ad.tar.gz |
SquareBoard : support negative coords
-rw-r--r-- | core/src/ch/asynk/gdx/board/board/SquareBoard.java | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/core/src/ch/asynk/gdx/board/board/SquareBoard.java b/core/src/ch/asynk/gdx/board/board/SquareBoard.java index 9485e20..3c68490 100644 --- a/core/src/ch/asynk/gdx/board/board/SquareBoard.java +++ b/core/src/ch/asynk/gdx/board/board/SquareBoard.java @@ -27,8 +27,12 @@ public class SquareBoard implements Board @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); + float dx = x - this.x0; + float dy = y - this.y0; + int col = (int) (dx / this.side); + int row = (int) (dy / this.side); + if (dx < 0) col -=1; + if (dy < 0) row -=1; v.set(col, row); } |