X-Git-Url: http://deadsoftware.ru/gitweb?p=cavedroid.git;a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavecraft%2Fgame%2FGameInput.java;h=e2877e3d23c267ec4c7faea3442c0884f36f2d9c;hp=8bfea89aad345ff07b257dba81527c258858bc2e;hb=22eccb137bf9642700f762dd39cf02ea144bdca3;hpb=1c798d88e9c23d438e7fa770c9670b02a761f866 diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java index 8bfea89..e2877e3 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java @@ -8,91 +8,87 @@ import ru.deadsoftware.cavecraft.game.mobs.Pig; import ru.deadsoftware.cavecraft.misc.AppState; import ru.deadsoftware.cavecraft.misc.Assets; -public class GameInput { - - private GameProc gp; +import static ru.deadsoftware.cavecraft.GameScreen.GP; - public GameInput(GameProc gp) { - this.gp = gp; - } +public class GameInput { private boolean checkSwim() { - return GameItems.isFluid(gp.world.getForeMap(gp.player.getMapX(), gp.player.getMapY())); + return GameItems.isFluid(GP.world.getForeMap(GP.player.getMapX(), GP.player.getMapY())); } private boolean insideCreativeInv(int screenX, int screenY) { - return (screenX > gp.renderer.getWidth() / 2 - Assets.creativeInv.getRegionWidth() / 2 && - screenX < gp.renderer.getWidth() / 2 + Assets.creativeInv.getRegionWidth() / 2 && - screenY > gp.renderer.getHeight() / 2 - Assets.creativeInv.getRegionHeight() / 2 && - screenY < gp.renderer.getHeight() / 2 + Assets.creativeInv.getRegionHeight() / 2); + return (screenX > GP.renderer.getWidth() / 2 - Assets.creativeInv.getRegionWidth() / 2 && + screenX < GP.renderer.getWidth() / 2 + Assets.creativeInv.getRegionWidth() / 2 && + screenY > GP.renderer.getHeight() / 2 - Assets.creativeInv.getRegionHeight() / 2 && + screenY < GP.renderer.getHeight() / 2 + Assets.creativeInv.getRegionHeight() / 2); } private void wasdPressed(int keycode) { - if (gp.ctrlMode == 0 || !CaveGame.TOUCH) { + if (GP.ctrlMode == 0 || !CaveGame.TOUCH) { switch (keycode) { case Input.Keys.A: - gp.player.mov.x = -GamePhysics.PL_SPEED; - gp.player.setDir(0); - if (CaveGame.TOUCH && checkSwim()) gp.player.swim = true; + GP.player.mov.x = -GamePhysics.PL_SPEED; + GP.player.setDir(0); + if (CaveGame.TOUCH && checkSwim()) GP.player.swim = true; break; case Input.Keys.D: - gp.player.mov.x = GamePhysics.PL_SPEED; - gp.player.setDir(1); - if (CaveGame.TOUCH && checkSwim()) gp.player.swim = true; + GP.player.mov.x = GamePhysics.PL_SPEED; + GP.player.setDir(1); + if (CaveGame.TOUCH && checkSwim()) GP.player.swim = true; break; } } else { switch (keycode) { case Input.Keys.A: - gp.curX--; + GP.curX--; break; case Input.Keys.D: - gp.curX++; + GP.curX++; break; case Input.Keys.W: - gp.curY--; + GP.curY--; break; case Input.Keys.S: - gp.curY++; + GP.curY++; break; } - gp.blockDmg = 0; + GP.blockDmg = 0; } } public void keyDown(int keycode) { - gp.isKeyDown = true; - gp.keyDownCode = keycode; + GP.isKeyDown = true; + GP.keyDownCode = keycode; if (keycode == Input.Keys.W || keycode == Input.Keys.A || keycode == Input.Keys.S || keycode == Input.Keys.D) { wasdPressed(keycode); } else switch (keycode) { case Input.Keys.ALT_LEFT: if (CaveGame.TOUCH) { - gp.ctrlMode++; - if (gp.ctrlMode > 1) gp.ctrlMode = 0; + GP.ctrlMode++; + if (GP.ctrlMode > 1) GP.ctrlMode = 0; } break; case Input.Keys.SPACE: if (checkSwim()) { - gp.player.swim = true; - } else if (gp.player.canJump) { - gp.player.mov.add(0, -7); - } else if (!gp.player.flyMode && gp.player.gameMode == 1) { - gp.player.flyMode = true; - gp.player.mov.y = 0; - } else if (gp.player.flyMode) { - gp.player.mov.y = -GamePhysics.PL_SPEED; + GP.player.swim = true; + } else if (GP.player.canJump) { + GP.player.mov.add(0, -7); + } else if (!GP.player.flyMode && GP.player.gameMode == 1) { + GP.player.flyMode = true; + GP.player.mov.y = 0; + } else if (GP.player.flyMode) { + GP.player.mov.y = -GamePhysics.PL_SPEED; } break; case Input.Keys.CONTROL_LEFT: - gp.player.mov.y = GamePhysics.PL_SPEED; + GP.player.mov.y = GamePhysics.PL_SPEED; break; case Input.Keys.E: - if (CaveGame.STATE == AppState.GAME_PLAY) switch (gp.player.gameMode) { + if (CaveGame.STATE == AppState.GAME_PLAY) switch (GP.player.gameMode) { case 0: //TODO survival inv break; @@ -104,7 +100,11 @@ public class GameInput { break; case Input.Keys.G: - gp.mobs.add(new Pig(gp.curX * 16, gp.curY * 16)); + GP.mobs.add(new Pig(GP.curX * 16, GP.curY * 16)); + break; + + case Input.Keys.Q: + GP.world.placeToForeground(GP.curX, GP.curY, 8); break; case Input.Keys.ESCAPE: @@ -122,68 +122,68 @@ public class GameInput { switch (keycode) { case Input.Keys.A: case Input.Keys.D: - gp.player.mov.x = 0; - if (CaveGame.TOUCH && gp.player.swim) gp.player.swim = false; + GP.player.mov.x = 0; + if (CaveGame.TOUCH && GP.player.swim) GP.player.swim = false; break; case Input.Keys.SPACE: case Input.Keys.CONTROL_LEFT: - if (gp.player.flyMode) gp.player.mov.y = 0; - if (gp.player.swim) gp.player.swim = false; + if (GP.player.flyMode) GP.player.mov.y = 0; + if (GP.player.swim) GP.player.swim = false; break; } } public void touchDown(int screenX, int screenY, int button) { - gp.touchDownTime = TimeUtils.millis(); - gp.isTouchDown = true; - gp.touchDownBtn = button; - gp.touchDownX = screenX; - gp.touchDownY = screenY; + GP.touchDownTime = TimeUtils.millis(); + GP.isTouchDown = true; + GP.touchDownBtn = button; + GP.touchDownX = screenX; + GP.touchDownY = screenY; } public void touchUp(int screenX, int screenY, int button) { - if (CaveGame.TOUCH && gp.isKeyDown) { - keyUp(gp.keyDownCode); - gp.isKeyDown = false; + if (CaveGame.TOUCH && GP.isKeyDown) { + keyUp(GP.keyDownCode); + GP.isKeyDown = false; } - if (gp.isTouchDown) { + if (GP.isTouchDown) { if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && insideCreativeInv(screenX, screenY)) { - int ix = (int) (screenX - (gp.renderer.getWidth() / 2 - Assets.creativeInv.getRegionWidth() / 2 + 8)) / 18; - int iy = (int) (screenY - (gp.renderer.getHeight() / 2 - Assets.creativeInv.getRegionHeight() / 2 + 18)) / 18; - int item = gp.creativeScroll * 8 + (ix + iy * 8); + int ix = (int) (screenX - (GP.renderer.getWidth() / 2 - Assets.creativeInv.getRegionWidth() / 2 + 8)) / 18; + int iy = (int) (screenY - (GP.renderer.getHeight() / 2 - Assets.creativeInv.getRegionHeight() / 2 + 18)) / 18; + int item = GP.creativeScroll * 8 + (ix + iy * 8); if (ix >= 8 || ix < 0 || iy < 0 || iy >= 5) item = -1; if (item >= 0 && item < GameItems.getItemsSize()) { for (int i = 8; i > 0; i--) { - gp.player.inv[i] = gp.player.inv[i - 1]; + GP.player.inv[i] = GP.player.inv[i - 1]; } - gp.player.inv[0] = item; + GP.player.inv[0] = item; } } else if (CaveGame.STATE == AppState.GAME_CREATIVE_INV) { CaveGame.STATE = AppState.GAME_PLAY; } else if (screenY < Assets.invBar.getRegionHeight() && - screenX > gp.renderer.getWidth() / 2 - Assets.invBar.getRegionWidth() / 2 && - screenX < gp.renderer.getWidth() / 2 + Assets.invBar.getRegionWidth() / 2) { - gp.player.invSlot = (int) ((screenX - (gp.renderer.getWidth() / 2 - Assets.invBar.getRegionWidth() / 2)) / 20); + screenX > GP.renderer.getWidth() / 2 - Assets.invBar.getRegionWidth() / 2 && + screenX < GP.renderer.getWidth() / 2 + Assets.invBar.getRegionWidth() / 2) { + GP.player.invSlot = (int) ((screenX - (GP.renderer.getWidth() / 2 - Assets.invBar.getRegionWidth() / 2)) / 20); } else if (button == Input.Buttons.RIGHT) { - gp.useItem(gp.curX, gp.curY, - gp.player.inv[gp.player.invSlot], false); + GP.useItem(GP.curX, GP.curY, + GP.player.inv[GP.player.invSlot], false); } else if (button == Input.Buttons.LEFT) { - gp.blockDmg = 0; + GP.blockDmg = 0; } } - gp.isTouchDown = false; + GP.isTouchDown = false; } public void touchDragged(int screenX, int screenY) { - if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && Math.abs(screenY - gp.touchDownY) > 16) { + if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && Math.abs(screenY - GP.touchDownY) > 16) { if (insideCreativeInv(screenX, screenY)) { - gp.creativeScroll -= (screenY - gp.touchDownY) / 16; - gp.touchDownX = screenX; - gp.touchDownY = screenY; - if (gp.creativeScroll < 0) gp.creativeScroll = 0; - if (gp.creativeScroll > gp.maxCreativeScroll) - gp.creativeScroll = gp.maxCreativeScroll; + GP.creativeScroll -= (screenY - GP.touchDownY) / 16; + GP.touchDownX = screenX; + GP.touchDownY = screenY; + if (GP.creativeScroll < 0) GP.creativeScroll = 0; + if (GP.creativeScroll > GP.maxCreativeScroll) + GP.creativeScroll = GP.maxCreativeScroll; } } } @@ -191,15 +191,15 @@ public class GameInput { public void scrolled(int amount) { switch (CaveGame.STATE) { case GAME_PLAY: - gp.player.invSlot += amount; - if (gp.player.invSlot < 0) gp.player.invSlot = 8; - if (gp.player.invSlot > 8) gp.player.invSlot = 0; + GP.player.invSlot += amount; + if (GP.player.invSlot < 0) GP.player.invSlot = 8; + if (GP.player.invSlot > 8) GP.player.invSlot = 0; break; case GAME_CREATIVE_INV: - gp.creativeScroll += amount; - if (gp.creativeScroll < 0) gp.creativeScroll = 0; - if (gp.creativeScroll > gp.maxCreativeScroll) - gp.creativeScroll = gp.maxCreativeScroll; + GP.creativeScroll += amount; + if (GP.creativeScroll < 0) GP.creativeScroll = 0; + if (GP.creativeScroll > GP.maxCreativeScroll) + GP.creativeScroll = GP.maxCreativeScroll; break; } }