diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-05-31 19:35:33 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-05-31 19:35:33 +0200 |
commit | 57bebfaade1651e4de7f5ff49063937b4f427c5b (patch) | |
tree | 4a767412ce7e1df28212670e4ade58a97c39ba07 /test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java | |
parent | 5fc05067bfcb75add378b93df3886a1c621d2ea9 (diff) | |
download | gdx-boardgame-57bebfaade1651e4de7f5ff49063937b4f427c5b.zip gdx-boardgame-57bebfaade1651e4de7f5ff49063937b4f427c5b.tar.gz |
BoardScreen : clean up touch management
Diffstat (limited to 'test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java')
-rw-r--r-- | test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java index c5306d3..6d762fa 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java @@ -73,36 +73,43 @@ public class BoardScreen extends AbstractScreen public boolean touch(float x, float y, boolean down) { board.toBoard(x, y, v); - GdxBoardTest.debug("BoardScreen", String.format("touchDown [%d;%d] => [%d;%d] => %d", (int)x, (int)y, (int)v.x, (int)v.y, board.genKey((int)v.x, (int)v.y))); - float d0 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.TCHEBYCHEV); - float d1 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.TAXICAB); - float d2 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.EUCLIDEAN); - if (board.isOnMap((int)v.x, (int)v.y)) { - GdxBoardTest.debug("BoardScreen", String.format(" from [%d;%d] => %d :: %d :: %f", (int)pos.x, (int)pos.y, (int)d0, (int)d1, d2)); - if (down) { - Tile tile = getTile((int)v.x, (int)v.y); - if (!dragging && panzer.isOn(tile)) { - dragging = true; - clearAdjacents(); - } else { - pos.set(v); - handleAdjacents(); - board.centerOf((int)v.x, (int)v.y, v); - panzer.centerOn(v.x, v.y); - panzer.setRotation(Orientation.fromR(panzer.getRotation()).left().r()); - GdxBoardTest.debug("BoardScreen", String.format(" => [%d;%d]", (int)v.x, (int)v.y)); - } + if (!board.isOnMap((int)v.x, (int)v.y)) + return false; + if (down) { + Tile tile = getTile((int)v.x, (int)v.y); + if (!dragging && panzer.isOn(tile)) { + dragging = true; + clearAdjacents(); } else { - if (dragging) { - handleAdjacents(); - panzer.dropOnBoard(board, v); - dragging = false; - } + touchInfo(x, y); + pos.set(v); + handleAdjacents(); + board.centerOf((int)v.x, (int)v.y, v); + panzer.centerOn(v.x, v.y); + panzer.setRotation(Orientation.fromR(panzer.getRotation()).left().r()); + GdxBoardTest.debug("BoardScreen", String.format(" => [%d;%d]", (int)v.x, (int)v.y)); + } + } else { + if (dragging) { + touchInfo(x, y); + handleAdjacents(); + panzer.dropOnBoard(board, v); + GdxBoardTest.debug("BoardScreen", String.format(" => [%d;%d]", (int)v.x, (int)v.y)); + dragging = false; } } return true; } + private void touchInfo(float x, float y) + { + GdxBoardTest.debug("BoardScreen", String.format("touchDown [%d;%d] => [%d;%d] => %d", (int)x, (int)y, (int)v.x, (int)v.y, board.genKey((int)v.x, (int)v.y))); + float d0 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.TCHEBYCHEV); + float d1 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.TAXICAB); + float d2 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.EUCLIDEAN); + GdxBoardTest.debug("BoardScreen", String.format(" from [%d;%d] => %d :: %d :: %f", (int)pos.x, (int)pos.y, (int)d0, (int)d1, d2)); + } + public boolean drag(float dx, float dy) { if (dragging) { |