DEADSOFTWARE

Autoswim on touch screen
authorfred-boy <fred-boy@protonmail.com>
Mon, 10 Sep 2018 11:34:47 +0000 (18:34 +0700)
committerfred-boy <fred-boy@protonmail.com>
Mon, 10 Sep 2018 11:34:47 +0000 (18:34 +0700)
core/src/ru/deadsoftware/cavecraft/game/GameInput.java
core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java

index d151ec6b3279ffae07fc3e1e279e72cf3bb3e0be..c868a8adcb4250bb29c3ccd51127ec6844a3fefb 100644 (file)
@@ -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;
         }
     }
index 244875d9adecb9fbb33c8e2e4882982d5aa01b76..28a8333214fe4983c95f7e3f5ea868f536384910 100644 (file)
@@ -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())) {