diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java
index 379f9301b782a07aa4eba9398093c3394338a2f8..dcc1615667226d96b352a3597160f1fdf4cc6def 100644 (file)
public class GameInput {
public class GameInput {
- private boolean keyDown, touchedDown;
+ private boolean keyDown, touchedDown, dragging;
private int keyDownCode, touchDownBtn;
private float touchDownX, touchDownY;
private int keyDownCode, touchDownBtn;
private float touchDownX, touchDownY;
case Input.Keys.A:
GP.player.getMove().x = -GamePhysics.PL_SPEED;
GP.player.setDir(Mob.Direction.LEFT);
case Input.Keys.A:
GP.player.getMove().x = -GamePhysics.PL_SPEED;
GP.player.setDir(Mob.Direction.LEFT);
- if (CaveGame.TOUCH && checkSwim()) GP.player.swim = true;
+ if (CaveGame.TOUCH && checkSwim()) {
+ GP.player.swim = true;
+ }
break;
case Input.Keys.D:
GP.player.getMove().x = GamePhysics.PL_SPEED;
GP.player.setDir(Mob.Direction.RIGHT);
break;
case Input.Keys.D:
GP.player.getMove().x = GamePhysics.PL_SPEED;
GP.player.setDir(Mob.Direction.RIGHT);
- if (CaveGame.TOUCH && checkSwim()) GP.player.swim = true;
+ if (CaveGame.TOUCH && checkSwim()) {
+ GP.player.swim = true;
+ }
break;
case Input.Keys.W:
case Input.Keys.SPACE:
break;
case Input.Keys.W:
case Input.Keys.SPACE:
curX += GP.player.looksLeft() ? 1 : -1;
}
} else if (!CaveGame.TOUCH) {
curX += GP.player.looksLeft() ? 1 : -1;
}
} else if (!CaveGame.TOUCH) {
- curX = (int) (Gdx.input.getX() * (GP.renderer.getWidth() / GameScreen.getWidth()) + GP.renderer.getCamX()) / 16;
- curY = (int) (Gdx.input.getY() * (GP.renderer.getHeight() / GameScreen.getHeight()) + GP.renderer.getCamY()) / 16;
- if (curX < 0) curX--;
+ curX = (int) (Gdx.input.getX() * (GP.renderer.getWidth() /
+ GameScreen.getWidth()) + GP.renderer.getCamX()) / 16;
+
+ curY = (int) (Gdx.input.getY() * (GP.renderer.getHeight() /
+ GameScreen.getHeight()) + GP.renderer.getCamY()) / 16;
+ if (curX < 0) {
+ curX--;
+ }
}
if (pastX != curX || pastY != curY) {
}
if (pastX != curX || pastY != curY) {
}
private void pressLMB() {
}
private void pressLMB() {
- if ((GP.world.hasForeAt(curX, curY) && GP.world.getForeMapBlock(curX, curY).getHp() >= 0) ||
+ if (CaveGame.GAME_STATE == GameState.PLAY &&
+ ((GP.world.hasForeAt(curX, curY) && GP.world.getForeMapBlock(curX, curY).getHp() >= 0) ||
(!GP.world.hasForeAt(curX, curY) && GP.world.hasBackAt(curX, curY) &&
(!GP.world.hasForeAt(curX, curY) && GP.world.hasBackAt(curX, curY) &&
- GP.world.getBackMapBlock(curX, curY).getHp() >= 0)) {
+ GP.world.getBackMapBlock(curX, curY).getHp() >= 0))) {
if (GP.player.gameMode == 0) {
blockDamage++;
if (GP.world.hasForeAt(curX, curY)) {
if (GP.player.gameMode == 0) {
blockDamage++;
if (GP.world.hasForeAt(curX, curY)) {
case Input.Keys.A:
case Input.Keys.D:
GP.player.getMove().x = 0;
case Input.Keys.A:
case Input.Keys.D:
GP.player.getMove().x = 0;
- if (CaveGame.TOUCH && GP.player.swim) GP.player.swim = false;
+ if (CaveGame.TOUCH && GP.player.swim) {
+ GP.player.swim = false;
+ }
break;
case Input.Keys.W:
case Input.Keys.S:
case Input.Keys.SPACE:
case Input.Keys.CONTROL_LEFT:
break;
case Input.Keys.W:
case Input.Keys.S:
case Input.Keys.SPACE:
case Input.Keys.CONTROL_LEFT:
- if (GP.player.isFlyMode()) GP.player.getMove().y = 0;
- if (GP.player.swim) GP.player.swim = false;
+ if (GP.player.isFlyMode()) {
+ GP.player.getMove().y = 0;
+ }
+ if (GP.player.swim) {
+ GP.player.swim = false;
+ }
break;
}
}
break;
}
}
}
public void touchUp(float screenX, float screenY, int button) {
}
public void touchUp(float screenX, float screenY, int button) {
+ if (dragging) {
+ dragging = false;
+ return;
+ }
+
if (CaveGame.TOUCH && keyDown) {
keyUp(keyDownCode);
keyDown = false;
if (CaveGame.TOUCH && keyDown) {
keyUp(keyDownCode);
keyDown = false;
int ix = (int) (screenX - (GP.renderer.getWidth() / 2 - creative.getRegionWidth() / 2 + 8)) / 18;
int iy = (int) (screenY - (GP.renderer.getHeight() / 2 - creative.getRegionHeight() / 2 + 18)) / 18;
int item = creativeScroll * 8 + (ix + iy * 8);
int ix = (int) (screenX - (GP.renderer.getWidth() / 2 - creative.getRegionWidth() / 2 + 8)) / 18;
int iy = (int) (screenY - (GP.renderer.getHeight() / 2 - creative.getRegionHeight() / 2 + 18)) / 18;
int item = creativeScroll * 8 + (ix + iy * 8);
- if (ix >= 8 || ix < 0 || iy < 0 || iy >= 5) item = -1;
+ if (ix >= 8 || ix < 0 || iy < 0 || iy >= 5) {
+ item = -1;
+ }
if (item >= 0 && item < GameItems.getItemsSize()) {
System.arraycopy(GP.player.inventory, 0, GP.player.inventory, 1, 8);
GP.player.inventory[0] = item;
if (item >= 0 && item < GameItems.getItemsSize()) {
System.arraycopy(GP.player.inventory, 0, GP.player.inventory, 1, 8);
GP.player.inventory[0] = item;
}
public void touchDragged(float screenX, float screenY) {
}
public void touchDragged(float screenX, float screenY) {
+ dragging = true;
if (CaveGame.GAME_STATE == GameState.CREATIVE_INV && Math.abs(screenY - touchDownY) > 16) {
if (insideCreativeInv(screenX, screenY)) {
creativeScroll -= (screenY - touchDownY) / 16;
touchDownX = screenX;
touchDownY = screenY;
if (CaveGame.GAME_STATE == GameState.CREATIVE_INV && Math.abs(screenY - touchDownY) > 16) {
if (insideCreativeInv(screenX, screenY)) {
creativeScroll -= (screenY - touchDownY) / 16;
touchDownX = screenX;
touchDownY = screenY;
- if (creativeScroll < 0) creativeScroll = 0;
- if (creativeScroll > GameProc.MAX_CREATIVE_SCROLL)
+ if (creativeScroll < 0) {
+ creativeScroll = 0;
+ }
+ if (creativeScroll > GameProc.MAX_CREATIVE_SCROLL) {
creativeScroll = GameProc.MAX_CREATIVE_SCROLL;
creativeScroll = GameProc.MAX_CREATIVE_SCROLL;
+ }
}
}
}
}
}
}
switch (CaveGame.GAME_STATE) {
case PLAY:
GP.player.slot += amount;
switch (CaveGame.GAME_STATE) {
case PLAY:
GP.player.slot += amount;
- if (GP.player.slot < 0) GP.player.slot = 8;
- if (GP.player.slot > 8) GP.player.slot = 0;
+ if (GP.player.slot < 0) {
+ GP.player.slot = 8;
+ }
+ if (GP.player.slot > 8) {
+ GP.player.slot = 0;
+ }
break;
case CREATIVE_INV:
creativeScroll += amount;
break;
case CREATIVE_INV:
creativeScroll += amount;
- if (creativeScroll < 0) creativeScroll = 0;
- if (creativeScroll > GameProc.MAX_CREATIVE_SCROLL)
+ if (creativeScroll < 0) {
+ creativeScroll = 0;
+ }
+ if (creativeScroll > GameProc.MAX_CREATIVE_SCROLL) {
creativeScroll = GameProc.MAX_CREATIVE_SCROLL;
creativeScroll = GameProc.MAX_CREATIVE_SCROLL;
+ }
break;
}
}
break;
}
}