DEADSOFTWARE

Fix touch controls
authorfred-boy <fredboy@protonmail.com>
Fri, 27 Sep 2019 19:17:25 +0000 (02:17 +0700)
committerfred-boy <fredboy@protonmail.com>
Sun, 29 Sep 2019 04:39:18 +0000 (11:39 +0700)
core/src/ru/deadsoftware/cavedroid/game/GameProc.java
core/src/ru/deadsoftware/cavedroid/misc/InputHandlerGame.java

index b3b0d3f51a186197c5fb5c1b26185f1388b7984e..4de979050583c688ef682ed3205ac2655bfcb3e0 100644 (file)
@@ -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;
+                }
         }
     }
 
index a84e22af7a72c1afae78fb199e9baa098fcfca60..c00521f1311570106c91e8aecc5d2b4a1458238e 100644 (file)
@@ -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);