From 19eb912d7ac7d2ef99f85ea4dd87c6611586891f Mon Sep 17 00:00:00 2001 From: fred-boy Date: Sun, 22 Apr 2018 00:24:32 +0700 Subject: [PATCH] Fix controls on Android --- .../cavecraft/game/GamePhysics.java | 1 + .../deadsoftware/cavecraft/game/GameProc.java | 42 +++++++++---------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index 2fdc29b..b20575a 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -24,6 +24,7 @@ public class GamePhysics { private boolean checkJump(Rectangle rect, int dir) { int bl = 0; + if (rect.x<0) rect.x-=16; switch (dir) { case 0: bl = gameProc.world.getForeMap( diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index 6c532ac..f3ea4ac 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -52,26 +52,22 @@ public class GameProc { } private void moveCursor() { - if (ctrlMode==0 && CaveGame.TOUCH) { - if (player.canJump) { - cursorX = (int) (player.position.x + player.texWidth / 2) / 16; - if (player.dir == 0) cursorX--; + if (ctrlMode == 0 && CaveGame.TOUCH) { + cursorX = (int) (player.position.x + player.texWidth / 2) / 16; + if (player.dir == 0) cursorX--; else cursorX++; - cursorY = (int) (player.position.y + player.texWidth) / 16; - if (!isAutoselectable(cursorX, cursorY)) { - cursorY++; - } - if (!isAutoselectable(cursorX, cursorY)) { - cursorY++; - } - if (!isAutoselectable(cursorX, cursorY)) { - if (player.dir == 0) cursorX++; - else cursorX--; - } - } else { - cursorX = (int) (player.position.x + player.texWidth / 2) / 16; - cursorY = (int) (player.position.y + player.height+8)/16; + cursorY = (int) (player.position.y + player.texWidth) / 16; + if (!isAutoselectable(cursorX, cursorY)) { + cursorY++; } + if (!isAutoselectable(cursorX, cursorY)) { + cursorY++; + } + if (!isAutoselectable(cursorX, cursorY)) { + if (player.dir == 0) cursorX++; + else cursorX--; + } + if (player.position.x<0) cursorX--; } else if (!CaveGame.TOUCH){ cursorX = (int)(Gdx.input.getX()* (renderer.camera.viewportWidth/GameScreen.getWidth())+renderer.camera.position.x)/16; @@ -86,10 +82,12 @@ public class GameProc { private void checkCursorBounds() { if (cursorY < 0) cursorY = 0; if (cursorY >= world.getHeight()) cursorY = world.getHeight()-1; - if (cursorX<(player.position.x+player.texWidth/2)/16) - player.dir=0; - if (cursorX>(player.position.x+player.texWidth/2)/16) - player.dir=1; + if (ctrlMode==1) { + if (cursorX*16+8player.position.x+player.texWidth/2) + player.dir=1; + } } public void update(float delta) { -- 2.29.2