From d4b230bcff9be349af3d450cf5fea0bf0ebf33b8 Mon Sep 17 00:00:00 2001 From: fred-boy Date: Thu, 26 Apr 2018 14:19:37 +0700 Subject: [PATCH] Attempt to make more convenient controls --- .../cavecraft/game/GameInput.java | 68 ++++++++++--------- .../deadsoftware/cavecraft/game/GameProc.java | 3 +- .../cavecraft/game/GameRenderer.java | 4 ++ .../cavecraft/misc/InputHandlerGame.java | 10 ++- 4 files changed, 49 insertions(+), 36 deletions(-) diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java index 2e54ad3..08f6e36 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java @@ -105,27 +105,9 @@ public class GameInput { } public void touchDown(int screenX, int screenY, int button) { - if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && - screenX>gameProc.renderer.camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2 && - screenXgameProc.renderer.camera.viewportHeight/2-Assets.creativeInv.getRegionHeight()/2 && - screenY= 0 && item < Items.BLOCKS.size) { - for (int i = 8; i > 0; i--) { - gameProc.player.inventory[i] = gameProc.player.inventory[i - 1]; - } - gameProc.player.inventory[0] = item; - } - } else if (CaveGame.STATE == AppState.GAME_CREATIVE_INV) { - CaveGame.STATE = AppState.GAME_PLAY; - } else { - gameProc.touchDownTime = TimeUtils.millis(); - gameProc.isTouchDown = true; - gameProc.touchDownButton = button; - } + gameProc.touchDownTime = TimeUtils.millis(); + gameProc.isTouchDown = true; + gameProc.touchDownButton = button; gameProc.touchDownX = screenX; gameProc.touchDownY = screenY; } @@ -136,15 +118,32 @@ public class GameInput { gameProc.isKeyDown = false; } if (gameProc.isTouchDown) { - if (button == Input.Buttons.RIGHT){ + if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && + screenX>gameProc.renderer.camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2 && + screenXgameProc.renderer.camera.viewportHeight/2-Assets.creativeInv.getRegionHeight()/2 && + screenY=8 || ix<0 || iy<0 || iy>=5) item=-1; + if (item >= 0 && item < Items.BLOCKS.size) { + for (int i = 8; i > 0; i--) { + gameProc.player.inventory[i] = gameProc.player.inventory[i - 1]; + } + gameProc.player.inventory[0] = item; + } + } else if (CaveGame.STATE == AppState.GAME_CREATIVE_INV) { + CaveGame.STATE = AppState.GAME_PLAY; + } else if (screenYgameProc.renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 && + screenXgameProc.renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 && - screenX 0) { + if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY) > 0) { gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 0); } else if (gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY) > 0) { gameProc.world.placeToBackground(gameProc.cursorX, gameProc.cursorY, 0); @@ -157,12 +156,19 @@ public class GameInput { public void touchDragged(int screenX, int screenY) { if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && Math.abs(screenY-gameProc.touchDownY)>16) { - gameProc.creativeScroll+=(screenY-gameProc.touchDownY)/16; + if (screenX>gameProc.renderer.camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2 && + screenXgameProc.renderer.camera.viewportHeight/2-Assets.creativeInv.getRegionHeight()/2 && + screenYgameProc.maxCreativeScroll) - gameProc.creativeScroll=gameProc.maxCreativeScroll; + if (gameProc.creativeScroll < 0) gameProc.creativeScroll = 0; + if (gameProc.creativeScroll > gameProc.maxCreativeScroll) + gameProc.creativeScroll = gameProc.maxCreativeScroll; + } } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java index 8f5dca2..5ba62a2 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameProc.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameProc.java @@ -121,8 +121,7 @@ public class GameProc implements Serializable{ if (touchDownButton== Input.Buttons.RIGHT) { world.placeToBackground(cursorX, cursorY, player.inventory[invSlot]); - } else if (touchDownButton==Input.Buttons.LEFT && - touchDownY< Assets.invBar.getRegionHeight() && + } else if (touchDownY< Assets.invBar.getRegionHeight() && touchDownX>renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 && touchDownX tWidth - 26 && screenY > ty - 26) { gameInput.touchDown(screenX, screenY, Input.Buttons.RIGHT); } else { - gameInput.touchDown(screenX, screenY, Input.Buttons.LEFT); + gameInput.touchDown(screenX, screenY, -1); } } else { gameInput.touchDown(screenX, screenY, button); @@ -97,7 +97,7 @@ public class InputHandlerGame implements InputProcessor { } else if (tx > tWidth - 26 && screenY > ty - 26) { gameInput.touchUp(screenX, screenY, Input.Buttons.RIGHT); } else { - gameInput.touchUp(screenX, screenY, Input.Buttons.LEFT); + gameInput.touchUp(screenX, screenY, -1); } } else { gameInput.touchUp(screenX, screenY, button); @@ -109,7 +109,11 @@ public class InputHandlerGame implements InputProcessor { public boolean touchDragged(int screenX, int screenY, int pointer) { screenX *= gameProc.renderer.camera.viewportWidth/getWidth(); screenY *= gameProc.renderer.camera.viewportHeight/getHeight(); - gameInput.touchDragged(screenX, screenY); + if (gameProc.isKeyDown && (screenX>78 || screenY