DEADSOFTWARE

Fix codestyle
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / GameInput.java
index df002fa8df09fd5d6e8836e5fb50e549f28c81ca..bef9b558bb2471f848033ddd884f1834c4cdd9b0 100644 (file)
@@ -33,6 +33,19 @@ public class GameInput {
         return GameItems.isFluid(GP.world.getForeMap(GP.player.getMapX(), GP.player.getLowerMapY()));
     }
 
+    private void goUpwards() {
+        if (checkSwim()) {
+            GP.player.swim = true;
+        } else if (GP.player.canJump()) {
+            GP.player.getMove().add(0, -7);
+        } else if (!GP.player.isFlyMode() && GP.player.gameMode == 1) {
+            GP.player.setFlyMode(true);
+            GP.player.getMove().y = 0;
+        } else if (GP.player.isFlyMode()) {
+            GP.player.getMove().y = -GamePhysics.PL_SPEED;
+        }
+    }
+
     @SuppressWarnings("IntegerDivisionInFloatingPointContext")
     private boolean insideCreativeInv(float screenX, float screenY) {
         TextureRegion creative = Assets.textureRegions.get("creative");
@@ -46,14 +59,26 @@ public class GameInput {
         if (GP.controlMode == ControlMode.WALK || !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.getMove().x = -GamePhysics.PL_SPEED;
+                    GP.player.setDir(Mob.Direction.LEFT);
+                    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.getMove().x = GamePhysics.PL_SPEED;
+                    GP.player.setDir(Mob.Direction.RIGHT);
+                    if (CaveGame.TOUCH && checkSwim()) {
+                        GP.player.swim = true;
+                    }
+                    break;
+                case Input.Keys.W:
+                case Input.Keys.SPACE:
+                    goUpwards();
+                    break;
+                case Input.Keys.S:
+                case Input.Keys.CONTROL_LEFT:
+                    GP.player.getMove().y = GamePhysics.PL_SPEED;
                     break;
             }
         } else {
@@ -87,10 +112,10 @@ public class GameInput {
         }
 
         if (GP.controlMode == ControlMode.CURSOR) {
-            if (curX * 16 + 8 < GP.player.pos.x + GP.player.getWidth() / 2) {
-                GP.player.setDir(Mob.LEFT);
+            if (curX * 16 + 8 < GP.player.getX() + GP.player.getWidth() / 2) {
+                GP.player.setDir(Mob.Direction.LEFT);
             } else {
-                GP.player.setDir(Mob.RIGHT);
+                GP.player.setDir(Mob.Direction.RIGHT);
             }
         }
     }
@@ -109,9 +134,14 @@ public class GameInput {
                 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) {
@@ -195,33 +225,22 @@ public class GameInput {
     public void keyDown(int keycode) {
         keyDown = true;
         keyDownCode = keycode;
-        if (keycode == Input.Keys.W || keycode == Input.Keys.A ||
-                keycode == Input.Keys.S || keycode == Input.Keys.D) {
-            wasdPressed(keycode);
-        } else switch (keycode) {
+        switch (keycode) {
+            case Input.Keys.A:
+            case Input.Keys.D:
+            case Input.Keys.W:
+            case Input.Keys.S:
+            case Input.Keys.SPACE:
+            case Input.Keys.CONTROL_LEFT:
+                wasdPressed(keycode);
+                break;
+
             case Input.Keys.ALT_LEFT:
                 if (CaveGame.TOUCH) {
                     GP.controlMode = GP.controlMode == ControlMode.WALK ? ControlMode.CURSOR : ControlMode.WALK;
                 }
                 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;
-                }
-                break;
-
-            case Input.Keys.CONTROL_LEFT:
-                GP.player.mov.y = GamePhysics.PL_SPEED;
-                break;
-
             case Input.Keys.E:
                 if (CaveGame.GAME_STATE == GameState.PLAY) {
                     switch (GP.player.gameMode) {
@@ -265,14 +284,22 @@ 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.getMove().x = 0;
+                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:
-                if (GP.player.flyMode) GP.player.mov.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;
         }
     }
@@ -297,7 +324,9 @@ public class GameInput {
                 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;
@@ -324,9 +353,12 @@ public class GameInput {
                 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;
+                }
             }
         }
     }
@@ -335,14 +367,21 @@ public class GameInput {
         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;
-                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;
+                }
                 break;
         }
     }