X-Git-Url: https://deadsoftware.ru/gitweb?p=cavedroid.git;a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavecraft%2Fgame%2FGameInputHandler.java;h=102a0f7b003f79471cca77e2dc3c65778debe6a3;hp=1273c05a7c6ebb97b0e3a17d6402b7a6ca7d788f;hb=769c26b45cc2bc91439f5f4f92bb7ac75fadfa91;hpb=5f7d6ee2ded67d412e861f09e102b52efb74d12c diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java b/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java index 1273c05..102a0f7 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInputHandler.java @@ -11,36 +11,93 @@ public class GameInputHandler { this.gameProc = gameProc; } - public void mouseMoved(int screenX, int screenY) { - gameProc.cursorX = (int)((screenX+gameProc.renderer.camera.position.x)/32); - gameProc.cursorY = (int)((screenY+gameProc.renderer.camera.position.y)/32); - if (gameProc.cursorX < 0) - gameProc.cursorX = 0; - if (gameProc.cursorX >= gameProc.world.getWidth()) - gameProc.cursorX = gameProc.world.getWidth()-1; - if (gameProc.cursorY < 0) - gameProc.cursorY = 0; - if (gameProc.cursorY >= gameProc.world.getHeight()) - gameProc.cursorY = gameProc.world.getHeight()-1; + public void keyDown(int keyCode) { + if (gameProc.ctrlMode==0) { + if (keyCode == Input.Keys.A) { + gameProc.player.moveX.add(-GamePhysics.PL_SPEED, 0); + gameProc.player.dir = 0; + } + if (keyCode == Input.Keys.D) { + gameProc.player.moveX.add(GamePhysics.PL_SPEED, 0); + gameProc.player.dir = 1; + } + } else { + if (keyCode == Input.Keys.A) { + gameProc.cursorX--; + } + if (keyCode == Input.Keys.D) { + gameProc.cursorX++; + } + if (keyCode == Input.Keys.W) { + gameProc.cursorY--; + } + if (keyCode == Input.Keys.S) { + gameProc.cursorY++; + } + if (gameProc.cursorX < 0) + gameProc.cursorX = 0; + if (gameProc.cursorX >= gameProc.world.getWidth()) + gameProc.cursorX = gameProc.world.getWidth()-1; + if (gameProc.cursorY < 0) + gameProc.cursorY = 0; + if (gameProc.cursorY >= gameProc.world.getHeight()) + gameProc.cursorY = gameProc.world.getHeight()-1; + } + if (keyCode == Input.Keys.ALT_LEFT) { + gameProc.ctrlMode++; + gameProc.cursorX = (int)(gameProc.player.position.x/16); + gameProc.cursorY = (int)(gameProc.player.position.y/16); + if (gameProc.ctrlMode > 1) gameProc.ctrlMode = 0; + } + if (keyCode == Input.Keys.SPACE) { + if (gameProc.player.canJump) { + gameProc.player.moveY.add(0, -7); + } else if (!gameProc.player.flyMode) { + gameProc.player.flyMode = true; + gameProc.player.moveY.setZero(); + } else { + gameProc.player.moveY.y = -GamePhysics.PL_SPEED; + } + } + if (keyCode == Input.Keys.CONTROL_LEFT) { + gameProc.player.moveY.y = GamePhysics.PL_SPEED; + } + } + public void keyUp(int keyCode) { + if (keyCode == Input.Keys.A || keyCode == Input.Keys.D) { + gameProc.player.moveX.x = 0; + } + if (keyCode == Input.Keys.SPACE) { + if (gameProc.player.flyMode) gameProc.player.moveY.setZero(); + } + if (keyCode == Input.Keys.CONTROL_LEFT) { + if (gameProc.player.flyMode) gameProc.player.moveY.setZero(); + } + } + + public void mouseMoved(int screenX, int screenY) { } public void touchDown(int screenX, int screenY, int button) { - if (button == Input.Buttons.LEFT) { - 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); - } - } else { - gameProc.touchDownTime = TimeUtils.millis(); - gameProc.isTouchDown = true; - } + gameProc.touchDownX = screenX; + gameProc.touchDownY = screenY; + gameProc.touchDownTime = TimeUtils.millis(); + gameProc.isTouchDown = true; } public void touchUp(int screenX, int screenY, int button) { - if (gameProc.isTouchDown && button == Input.Buttons.RIGHT){ - gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 1); + if (gameProc.isTouchDown) { + if (button == Input.Buttons.RIGHT){ + gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, + gameProc.player.inventory[gameProc.invSlot]); + } else if (button == Input.Buttons.LEFT) { + 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); + } + } } gameProc.isTouchDown = false; } @@ -48,4 +105,10 @@ public class GameInputHandler { public void touchDragged(int screenX, int screenY) { } + public void scrolled(int amount) { + gameProc.invSlot += amount; + if (gameProc.invSlot < 0) gameProc.invSlot = 8; + if (gameProc.invSlot > 8) gameProc.invSlot = 0; + } + }