From b35b61953623857f911255a88a6f2268076ee8ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 14 Sep 2018 15:31:41 +0200 Subject: SquareBoard : support negative coords --- core/src/ch/asynk/gdx/board/board/SquareBoard.java | 8 ++++++-- 1 file 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); } -- cgit v1.1-2-g2b99