From ba457424d8669a21df8352bdb77fc327332bc096 Mon Sep 17 00:00:00 2001 From: fred-boy Date: Sat, 28 Sep 2019 02:17:25 +0700 Subject: [PATCH] Fix touch controls --- .../deadsoftware/cavedroid/game/GameProc.java | 30 +++++++++++-------- .../cavedroid/misc/InputHandlerGame.java | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java index b3b0d3f..4de9790 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java @@ -95,12 +95,12 @@ public class GameProc implements Serializable, Disposable { int pastY = curY; if (controlMode == ControlMode.WALK && CaveGame.TOUCH) { - curX = player.getMapX(); - curY = (int) (player.pos.y + player.getWidth() / 16); - while (curY - pastY < 2 && isNotAutoselectable(curX, curY)) { + curX = player.getMapX() + (player.looksLeft() ? -1 : 1); + curY = player.getUpperMapY(); + for (int i = 0; i < 2 && isNotAutoselectable(curX, curY); i++) { curY++; } - if (!isNotAutoselectable(curX, curY)) { + if (isNotAutoselectable(curX, curY)) { curX += player.looksLeft() ? 1 : -1; } } else if (!CaveGame.TOUCH) { @@ -212,16 +212,20 @@ public class GameProc implements Serializable, Disposable { } private void holdMB() { - if (touchDownBtn == Input.Buttons.RIGHT) { - useItem(curX, curY, player.inventory[player.slot], true); - isTouchDown = false; - } else if (touchDownBtn == Input.Buttons.LEFT) { - if (touchDownY < Assets.invBar.getRegionHeight() && - touchDownX > renderer.getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 && - touchDownX < renderer.getWidth() / 2 + (float) Assets.invBar.getRegionWidth() / 2) { - CaveGame.GAME_STATE= GameState.CREATIVE_INV; + switch (touchDownBtn) { + case Input.Buttons.RIGHT: + useItem(curX, curY, player.inventory[player.slot], true); isTouchDown = false; - } + break; + case Input.Buttons.LEFT: + break; + default: + if (touchDownY < Assets.invBar.getRegionHeight() && + touchDownX > renderer.getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 && + touchDownX < renderer.getWidth() / 2 + (float) Assets.invBar.getRegionWidth() / 2) { + CaveGame.GAME_STATE= GameState.CREATIVE_INV; + isTouchDown = false; + } } } diff --git a/core/src/ru/deadsoftware/cavedroid/misc/InputHandlerGame.java b/core/src/ru/deadsoftware/cavedroid/misc/InputHandlerGame.java index a84e22a..c00521f 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/InputHandlerGame.java +++ b/core/src/ru/deadsoftware/cavedroid/misc/InputHandlerGame.java @@ -40,7 +40,7 @@ public class InputHandlerGame implements InputProcessor { if (CaveGame.TOUCH) { if (screenX > 26 && screenX < 52 && screenY > GP.renderer.getHeight() - 52 && screenY < GP.renderer.getHeight() - 26) { - if (GP.controlMode == ControlMode.WALK) { + if (GP.controlMode == ControlMode.CURSOR) { gameInput.keyDown(Input.Keys.W); } else { gameInput.keyDown(Input.Keys.SPACE); -- 2.29.2