From 35747c23579243d40294f923b35b23046329f1cd Mon Sep 17 00:00:00 2001 From: fred-boy Date: Mon, 10 Sep 2018 18:34:47 +0700 Subject: [PATCH] Autoswim on touch screen --- .../src/ru/deadsoftware/cavecraft/game/GameInput.java | 11 ++++++++--- .../ru/deadsoftware/cavecraft/game/GamePhysics.java | 6 +++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java index d151ec6..c868a8a 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameInput.java @@ -17,6 +17,11 @@ public class GameInput { this.gameProc = gameProc; } + private boolean checkSwim() { + return (CaveGame.TOUCH && Items.isFluid(gameProc.world.getForeMap((int)(gameProc.player.position.x+gameProc.player.width/2)/16, + (int)(gameProc.player.position.y+gameProc.player.height/4*3)/16))); + } + private void wasdPressed(int keycode) { if (gameProc.ctrlMode==0 || !CaveGame.TOUCH) { switch (keycode) { @@ -62,8 +67,7 @@ public class GameInput { break; case Input.Keys.SPACE: - if (Items.isFluid(gameProc.world.getForeMap((int)(gameProc.player.position.x+gameProc.player.width/2)/16, - (int)(gameProc.player.position.y+gameProc.player.height/4*3)/16))) { + if (checkSwim()) { gameProc.swim = true; } else if (gameProc.player.canJump) { gameProc.player.moveY.add(0, -7); @@ -102,11 +106,12 @@ public class GameInput { switch (keycode) { case Input.Keys.A: case Input.Keys.D: gameProc.player.moveX.x = 0; + if (gameProc.swim) gameProc.swim = false; break; case Input.Keys.SPACE: case Input.Keys.CONTROL_LEFT: if (gameProc.player.flyMode) gameProc.player.moveY.setZero(); - gameProc.swim = false; + if (gameProc.swim) gameProc.swim = false; break; } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index 244875d..28a8333 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -84,6 +84,7 @@ public class GamePhysics { } if (Items.isFluid(getBlock(pl.getRect()))) { + if (CaveGame.TOUCH && pl.moveX.x!=0 && !gameProc.swim && !pl.flyMode) gameProc.swim = true; if (!gameProc.swim) { if (!pl.flyMode && pl.moveY.y < 9) pl.moveY.add(gravity.x / 2, gravity.y / 2); if (!pl.flyMode && pl.moveY.y > 9) pl.moveY.add(0, -.9f); @@ -91,7 +92,10 @@ public class GamePhysics { pl.moveY.add(0, -.5f); if (pl.moveY.y<-3) pl.moveY.y = -3; } - } else if (!pl.flyMode && pl.moveY.y<18) pl.moveY.add(gravity); + } else { + if (!pl.flyMode && pl.moveY.y<18) pl.moveY.add(gravity); + if (CaveGame.TOUCH && gameProc.swim) gameProc.swim = false; + } pl.position.add(pl.moveX); if (checkColl(pl.getRect())) { -- 2.29.2