DEADSOFTWARE

Move some methods
authorfred-boy <fredboy@protonmail.com>
Sat, 28 Sep 2019 16:32:56 +0000 (23:32 +0700)
committerfred-boy <fredboy@protonmail.com>
Sun, 29 Sep 2019 04:39:18 +0000 (11:39 +0700)
GameProc => GameInput

core/src/ru/deadsoftware/cavedroid/game/GameInput.java
core/src/ru/deadsoftware/cavedroid/game/GameProc.java
core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java
core/src/ru/deadsoftware/cavedroid/game/GameSaver.java
core/src/ru/deadsoftware/cavedroid/misc/InputHandlerGame.java

index 32672ed2ca3223a8efc9846999816e6cf56aee77..df002fa8df09fd5d6e8836e5fb50e549f28c81ca 100644 (file)
@@ -1,10 +1,13 @@
 package ru.deadsoftware.cavedroid.game;
 
+import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.Input;
 import com.badlogic.gdx.graphics.g2d.TextureRegion;
 import com.badlogic.gdx.utils.TimeUtils;
+import com.google.common.collect.Range;
 import ru.deadsoftware.cavedroid.CaveGame;
 import ru.deadsoftware.cavedroid.GameScreen;
+import ru.deadsoftware.cavedroid.game.mobs.Mob;
 import ru.deadsoftware.cavedroid.game.mobs.Pig;
 import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.ControlMode;
@@ -12,9 +15,20 @@ import ru.deadsoftware.cavedroid.misc.states.AppState;
 import ru.deadsoftware.cavedroid.misc.states.GameState;
 
 import static ru.deadsoftware.cavedroid.GameScreen.GP;
+import static ru.deadsoftware.cavedroid.game.GameItems.*;
 
 public class GameInput {
 
+    private boolean keyDown, touchedDown;
+
+    private int keyDownCode, touchDownBtn;
+    private float touchDownX, touchDownY;
+    private long touchDownTime;
+
+    private int curX, curY;
+    private int creativeScroll;
+    private int blockDamage;
+
     private boolean checkSwim() {
         return GameItems.isFluid(GP.world.getForeMap(GP.player.getMapX(), GP.player.getLowerMapY()));
     }
@@ -45,25 +59,142 @@ public class GameInput {
         } else {
             switch (keycode) {
                 case Input.Keys.A:
-                    GP.curX--;
+                    curX--;
                     break;
                 case Input.Keys.D:
-                    GP.curX++;
+                    curX++;
                     break;
                 case Input.Keys.W:
-                    GP.curY--;
+                    curY--;
                     break;
                 case Input.Keys.S:
-                    GP.curY++;
+                    curY++;
                     break;
             }
-            GP.blockDmg = 0;
+            blockDamage = 0;
+        }
+    }
+
+    private boolean isNotAutoselectable(int x, int y) {
+        return (!GP.world.hasForeAt(x, y) || !GP.world.getForeMapBlock(x, y).hasCollision());
+    }
+
+    private void checkCursorBounds() {
+        if (curY < 0) {
+            curY = 0;
+        } else if (curY >= GP.world.getHeight()) {
+            curY = GP.world.getHeight() - 1;
+        }
+
+        if (GP.controlMode == ControlMode.CURSOR) {
+            if (curX * 16 + 8 < GP.player.pos.x + GP.player.getWidth() / 2) {
+                GP.player.setDir(Mob.LEFT);
+            } else {
+                GP.player.setDir(Mob.RIGHT);
+            }
+        }
+    }
+
+    private void moveCursor() {
+        int pastX = curX;
+        int pastY = curY;
+
+        if (GP.controlMode == ControlMode.WALK && CaveGame.TOUCH) {
+            curX = GP.player.getMapX() + (GP.player.looksLeft() ? -1 : 1);
+            curY = GP.player.getUpperMapY();
+            for (int i = 0; i < 2 && isNotAutoselectable(curX, curY); i++) {
+                curY++;
+            }
+            if (isNotAutoselectable(curX, curY)) {
+                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--;
+        }
+
+        if (pastX != curX || pastY != curY) {
+            blockDamage = 0;
+        }
+
+        checkCursorBounds();
+    }
+
+    private void useItem(int x, int y, int id, boolean bg) {
+        String key = getItem(id).isBlock() ? getBlockKey(id) : getItemKey(id);
+        if (id > 0) {
+            if (getItem(id).isBlock()) {
+                if (!bg) {
+                    GP.world.placeToForeground(x, y, getBlockIdByItemId(id));
+                } else {
+                    GP.world.placeToBackground(x, y, getBlockIdByItemId(id));
+                }
+            } else {
+                switch (key) {
+                    case "bucket_water":
+                        GP.world.placeToForeground(x, y, getBlockId("water"));
+                        GP.player.inventory[GP.player.slot] = getItemId("bucket_empty");
+                        break;
+                    case "bucket_lava":
+                        GP.world.placeToForeground(x, y, getBlockId("lava"));
+                        GP.player.inventory[GP.player.slot] = getItemId("bucket_empty");
+                        break;
+                }
+            }
+        }
+    }
+
+    private void pressLMB() {
+        if ((GP.world.hasForeAt(curX, curY) && GP.world.getForeMapBlock(curX, curY).getHp() >= 0) ||
+                (!GP.world.hasForeAt(curX, curY) && GP.world.hasBackAt(curX, curY) &&
+                        GP.world.getBackMapBlock(curX, curY).getHp() >= 0)) {
+            if (GP.player.gameMode == 0) {
+                blockDamage++;
+                if (GP.world.hasForeAt(curX, curY)) {
+                    if (blockDamage >= GP.world.getForeMapBlock(curX, curY).getHp()) {
+                        GP.world.destroyForeMap(curX, curY);
+                        blockDamage = 0;
+                    }
+                } else if (GP.world.hasBackAt(curX, curY)) {
+                    if (blockDamage >= GP.world.getBackMapBlock(curX, curY).getHp()) {
+                        GP.world.destroyBackMap(curX, curY);
+                        blockDamage = 0;
+                    }
+                }
+            } else {
+                if (GP.world.hasForeAt(curX, curY)) {
+                    GP.world.placeToForeground(curX, curY, 0);
+                } else if (GP.world.hasBackAt(curX, curY)) {
+                    GP.world.placeToBackground(curX, curY, 0);
+                }
+                touchedDown = false;
+            }
+        }
+    }
+
+    private boolean insideHotbar(float x, float y) {
+        TextureRegion hotbar = Assets.textureRegions.get("hotbar");
+        return y < hotbar.getRegionHeight() &&
+                Range.open(GP.renderer.getWidth() / 2 - (float) hotbar.getRegionWidth() / 2,
+                        GP.renderer.getWidth() / 2 + (float) hotbar.getRegionWidth() / 2).contains(x);
+    }
+
+    private void holdMB() {
+        if (touchDownBtn == Input.Buttons.RIGHT) {
+            useItem(curX, curY, GP.player.inventory[GP.player.slot], true);
+            touchedDown = false;
+        } else {
+            if (insideHotbar(touchDownX, touchDownY)) {
+                CaveGame.GAME_STATE = GameState.CREATIVE_INV;
+                touchedDown = false;
+            }
         }
     }
 
     public void keyDown(int keycode) {
-        GP.isKeyDown = true;
-        GP.keyDownCode = keycode;
+        keyDown = true;
+        keyDownCode = keycode;
         if (keycode == Input.Keys.W || keycode == Input.Keys.A ||
                 keycode == Input.Keys.S || keycode == Input.Keys.D) {
             wasdPressed(keycode);
@@ -92,7 +223,7 @@ public class GameInput {
                 break;
 
             case Input.Keys.E:
-                if (CaveGame.GAME_STATE == GameState.PLAY){
+                if (CaveGame.GAME_STATE == GameState.PLAY) {
                     switch (GP.player.gameMode) {
                         case 0:
                             //TODO survival inv
@@ -107,11 +238,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(curX * 16, curY * 16));
                 break;
 
             case Input.Keys.Q:
-                GP.world.placeToForeground(GP.curX, GP.curY, 8);
+                GP.world.placeToForeground(curX, curY, 8);
                 break;
 
             case Input.Keys.ESCAPE:
@@ -147,25 +278,25 @@ public class GameInput {
     }
 
     public void touchDown(float touchX, float touchY, int button) {
-        GP.touchDownTime = TimeUtils.millis();
-        GP.isTouchDown = true;
-        GP.touchDownBtn = button;
-        GP.touchDownX = touchX;
-        GP.touchDownY = touchY;
+        touchDownTime = TimeUtils.millis();
+        touchedDown = true;
+        touchDownBtn = button;
+        touchDownX = touchX;
+        touchDownY = touchY;
     }
 
     public void touchUp(float screenX, float screenY, int button) {
-        if (CaveGame.TOUCH && GP.isKeyDown) {
-            keyUp(GP.keyDownCode);
-            GP.isKeyDown = false;
+        if (CaveGame.TOUCH && keyDown) {
+            keyUp(keyDownCode);
+            keyDown = false;
         }
         TextureRegion hotbar = Assets.textureRegions.get("hotbar");
         TextureRegion creative = Assets.textureRegions.get("creative");
-        if (GP.isTouchDown) {
+        if (touchedDown) {
             if (CaveGame.GAME_STATE == GameState.CREATIVE_INV && insideCreativeInv(screenX, screenY)) {
                 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 = GP.creativeScroll * 8 + (ix + iy * 8);
+                int item = creativeScroll * 8 + (ix + iy * 8);
                 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);
@@ -178,24 +309,24 @@ public class GameInput {
                     screenX < GP.renderer.getWidth() / 2 + (float) hotbar.getRegionWidth() / 2) {
                 GP.player.slot = (int) ((screenX - (GP.renderer.getWidth() / 2 - hotbar.getRegionWidth() / 2)) / 20);
             } else if (button == Input.Buttons.RIGHT) {
-                GP.useItem(GP.curX, GP.curY,
+                useItem(curX, curY,
                         GP.player.inventory[GP.player.slot], false);
             } else if (button == Input.Buttons.LEFT) {
-                GP.blockDmg = 0;
+                blockDamage = 0;
             }
         }
-        GP.isTouchDown = false;
+        touchedDown = false;
     }
 
     public void touchDragged(float screenX, float screenY) {
-        if (CaveGame.GAME_STATE == GameState.CREATIVE_INV && Math.abs(screenY - GP.touchDownY) > 16) {
+        if (CaveGame.GAME_STATE == GameState.CREATIVE_INV && Math.abs(screenY - 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 > GameProc.MAX_CREATIVE_SCROLL)
-                    GP.creativeScroll = GameProc.MAX_CREATIVE_SCROLL;
+                creativeScroll -= (screenY - touchDownY) / 16;
+                touchDownX = screenX;
+                touchDownY = screenY;
+                if (creativeScroll < 0) creativeScroll = 0;
+                if (creativeScroll > GameProc.MAX_CREATIVE_SCROLL)
+                    creativeScroll = GameProc.MAX_CREATIVE_SCROLL;
             }
         }
     }
@@ -208,12 +339,46 @@ public class GameInput {
                 if (GP.player.slot > 8) GP.player.slot = 0;
                 break;
             case CREATIVE_INV:
-                GP.creativeScroll += amount;
-                if (GP.creativeScroll < 0) GP.creativeScroll = 0;
-                if (GP.creativeScroll > GameProc.MAX_CREATIVE_SCROLL)
-                    GP.creativeScroll = GameProc.MAX_CREATIVE_SCROLL;
+                creativeScroll += amount;
+                if (creativeScroll < 0) creativeScroll = 0;
+                if (creativeScroll > GameProc.MAX_CREATIVE_SCROLL)
+                    creativeScroll = GameProc.MAX_CREATIVE_SCROLL;
                 break;
         }
     }
 
+    public int getKeyDownCode() {
+        return keyDownCode;
+    }
+
+    public boolean isKeyDown() {
+        return keyDown;
+    }
+
+    int getBlockDamage() {
+        return blockDamage;
+    }
+
+    int getCurX() {
+        return curX;
+    }
+
+    int getCurY() {
+        return curY;
+    }
+
+    int getCreativeScroll() {
+        return creativeScroll;
+    }
+
+    void update() {
+        moveCursor();
+        if (touchedDown && touchDownBtn == Input.Buttons.LEFT) {
+            pressLMB();
+        }
+        if (touchedDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) {
+            holdMB();
+        }
+    }
+
 }
index 432ff51ef1828deafc26a47aa973eb5e37d4d576..60be6ebb4d395b1a46ac71b70dc43fad880db34f 100644 (file)
@@ -1,11 +1,7 @@
 package ru.deadsoftware.cavedroid.game;
 
 import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.Input;
-import com.badlogic.gdx.graphics.g2d.TextureRegion;
 import com.badlogic.gdx.utils.Disposable;
-import com.badlogic.gdx.utils.TimeUtils;
-import com.google.common.collect.Range;
 import ru.deadsoftware.cavedroid.CaveGame;
 import ru.deadsoftware.cavedroid.GameScreen;
 import ru.deadsoftware.cavedroid.game.mobs.FallingGravel;
@@ -13,18 +9,14 @@ import ru.deadsoftware.cavedroid.game.mobs.FallingSand;
 import ru.deadsoftware.cavedroid.game.mobs.Mob;
 import ru.deadsoftware.cavedroid.game.objects.Drop;
 import ru.deadsoftware.cavedroid.game.objects.Player;
-import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.ControlMode;
-import ru.deadsoftware.cavedroid.misc.states.GameState;
 
 import java.io.Serializable;
 import java.util.ArrayList;
 
-import static ru.deadsoftware.cavedroid.game.GameItems.*;
-
 public class GameProc implements Serializable, Disposable {
 
-    static final int MAX_CREATIVE_SCROLL = getItemsSize() / 8;
+    static final int MAX_CREATIVE_SCROLL = GameItems.getItemsSize() / 8;
 
     private static final int WORLD_WIDTH = 1024;
     private static final int WORLD_HEIGHT = 256;
@@ -36,6 +28,7 @@ public class GameProc implements Serializable, Disposable {
     private transient GameFluidsThread fluidThread;
     public transient GameWorld world;
     public transient GameRenderer renderer;
+    public transient GameInput input;
     transient GamePhysics physics;
 
     public ControlMode controlMode;
@@ -43,16 +36,10 @@ public class GameProc implements Serializable, Disposable {
     public ArrayList<Mob> mobs;
     ArrayList<Drop> drops;
 
-    public boolean isKeyDown;
-    public int keyDownCode;
-    boolean isTouchDown;
-    float touchDownX, touchDownY;
-    int touchDownBtn;
-    long touchDownTime;
-
-    int curX, curY;
-    int creativeScroll;
-    int blockDmg = 0;
+    public void resetRenderer() {
+        int scale = CaveGame.TOUCH ? 320 : 480;
+        renderer = new GameRenderer(scale, scale * GameScreen.getHeight() / GameScreen.getWidth());
+    }
 
     public GameProc(int gameMode) {
         world = new GameWorld(WORLD_WIDTH, WORLD_HEIGHT);
@@ -60,67 +47,17 @@ public class GameProc implements Serializable, Disposable {
         drops = new ArrayList<>();
         mobs = new ArrayList<>();
         physics = new GamePhysics();
+        input = new GameInput();
         controlMode = CaveGame.TOUCH ? ControlMode.WALK : ControlMode.CURSOR;
         resetRenderer();
         startFluidThread();
     }
 
-    public void resetRenderer() {
-        int scale = CaveGame.TOUCH ? 320 : 480;
-        renderer = new GameRenderer(scale, scale * GameScreen.getHeight() / GameScreen.getWidth());
-    }
-
     private void startFluidThread() {
         fluidThread = new GameFluidsThread();
         fluidThread.start();
     }
 
-    private boolean isNotAutoselectable(int x, int y) {
-        return (!world.hasForeAt(x, y) || !world.getForeMapBlock(x, y).hasCollision());
-    }
-
-    private void checkCursorBounds() {
-        if (curY < 0) {
-            curY = 0;
-        } else if (curY >= world.getHeight()) {
-            curY = world.getHeight() - 1;
-        }
-
-        if (controlMode == ControlMode.CURSOR) {
-            if (curX * 16 + 8 < player.pos.x + player.getWidth() / 2) {
-                player.setDir(0);
-            } else {
-                player.setDir(1);
-            }
-        }
-    }
-
-    private void moveCursor() {
-        int pastX = curX;
-        int pastY = curY;
-
-        if (controlMode == ControlMode.WALK && CaveGame.TOUCH) {
-            curX = player.getMapX() + (player.looksLeft() ? -1 : 1);
-            curY = player.getUpperMapY();
-            for (int i = 0; i < 2 && isNotAutoselectable(curX, curY); i++) {
-                curY++;
-            }
-            if (isNotAutoselectable(curX, curY)) {
-                curX += player.looksLeft() ? 1 : -1;
-            }
-        } else if (!CaveGame.TOUCH) {
-            curX = (int) (Gdx.input.getX() * (renderer.getWidth() / GameScreen.getWidth()) + renderer.getCamX()) / 16;
-            curY = (int) (Gdx.input.getY() * (renderer.getHeight() / GameScreen.getHeight()) + renderer.getCamY()) / 16;
-            if (curX < 0) curX--;
-        }
-
-        if (pastX != curX || pastY != curY) {
-            blockDmg = 0;
-        }
-
-        checkCursorBounds();
-    }
-
     private void updateBlock(int x, int y) {
         if (world.getForeMap(x, y) == 10) {
             if (!world.hasForeAt(x, y + 1) || !world.getForeMapBlock(x, y + 1).hasCollision()) {
@@ -147,7 +84,7 @@ public class GameProc implements Serializable, Disposable {
 
         if (world.getForeMap(x, y) == 2) {
             if (world.hasForeAt(x, y - 1) && (world.getForeMapBlock(x, y - 1).hasCollision() ||
-                    isFluid(world.getForeMap(x, y - 1)))) {
+                    GameItems.isFluid(world.getForeMap(x, y - 1)))) {
                 world.setForeMap(x, y, 3);
             }
         }
@@ -164,83 +101,10 @@ public class GameProc implements Serializable, Disposable {
         }
     }
 
-    void useItem(int x, int y, int id, boolean bg) {
-        String key = getItem(id).isBlock() ? getBlockKey(id) : getItemKey(id);
-        if (id > 0) {
-            if (getItem(id).isBlock()) {
-                if (!bg) {
-                    world.placeToForeground(x, y, getBlockIdByItemId(id));
-                } else {
-                    world.placeToBackground(x, y, getBlockIdByItemId(id));
-                }
-            } else {
-                switch (key) {
-                    case "bucket_water":
-                        world.placeToForeground(x, y, getBlockId("water"));
-                        player.inventory[player.slot] = getItemId("bucket_empty");
-                        break;
-                    case "bucket_lava":
-                        world.placeToForeground(x, y, getBlockId("lava"));
-                        player.inventory[player.slot] = getItemId("bucket_empty");
-                        break;
-                }
-            }
-        }
-    }
-
-    private void pressLMB() {
-        if ((world.hasForeAt(curX, curY) && world.getForeMapBlock(curX, curY).getHp() >= 0) ||
-                (!world.hasForeAt(curX, curY) && world.hasBackAt(curX, curY) &&
-                        world.getBackMapBlock(curX, curY).getHp() >= 0)) {
-            if (player.gameMode == 0) {
-                blockDmg++;
-                if (world.hasForeAt(curX, curY)) {
-                    if (blockDmg >= world.getForeMapBlock(curX, curY).getHp()) {
-                        world.destroyForeMap(curX, curY);
-                        blockDmg = 0;
-                    }
-                } else if (world.hasBackAt(curX, curY)) {
-                    if (blockDmg >= world.getBackMapBlock(curX, curY).getHp()) {
-                        world.destroyBackMap(curX, curY);
-                        blockDmg = 0;
-                    }
-                }
-            } else {
-                if (world.hasForeAt(curX, curY)) {
-                    world.placeToForeground(curX, curY, 0);
-                } else if (world.hasBackAt(curX, curY)) {
-                    world.placeToBackground(curX, curY, 0);
-                }
-                isTouchDown = false;
-            }
-        }
-    }
-
-    private boolean insideHotbar(float x, float y) {
-        TextureRegion hotbar = Assets.textureRegions.get("hotbar");
-        return y < hotbar.getRegionHeight() &&
-                Range.open(renderer.getWidth() / 2 - (float) hotbar.getRegionWidth() / 2,
-                        renderer.getWidth() / 2 + (float) hotbar.getRegionWidth() / 2).contains(x);
-    }
-
-    private void holdMB() {
-        if (touchDownBtn == Input.Buttons.RIGHT) {
-            useItem(curX, curY, player.inventory[player.slot], true);
-            isTouchDown = false;
-        } else {
-            if (insideHotbar(touchDownX, touchDownY)) {
-                CaveGame.GAME_STATE = GameState.CREATIVE_INV;
-                isTouchDown = false;
-            }
-        }
-    }
-
     public void update() {
         physics.update();
+        input.update();
         blockUpdater();
-        moveCursor();
-        if (isTouchDown && touchDownBtn == Input.Buttons.LEFT) pressLMB();
-        if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) holdMB();
         if (fluidThread == null || !fluidThread.isAlive()) startFluidThread();
     }
 
index 389994636043d1b7985bb13a411977d82a8d1b00..b45479914086c5f8474023502866d4f295b3ddda 100644 (file)
@@ -33,10 +33,10 @@ public class GameRenderer extends Renderer {
     }
 
     private void drawWreck(int bl) {
-        if (GP.blockDmg > 0) {
-            int index = 10 * GP.blockDmg / GameItems.getBlock(bl).getHp();
+        if (GP.input.getBlockDamage() > 0) {
+            int index = 10 * GP.input.getBlockDamage() / GameItems.getBlock(bl).getHp();
             String key = "break_" + index;
-            spriter.draw(textureRegions.get(key), GP.curX * 16 - getCamX(), GP.curY * 16 - getCamY());
+            spriter.draw(textureRegions.get(key), GP.input.getCurX() * 16 - getCamX(), GP.input.getCurY() * 16 - getCamY());
         }
     }
 
@@ -45,14 +45,14 @@ public class GameRenderer extends Renderer {
             if ((!GP.world.hasForeAt(x, y) || GP.world.getForeMapBlock(x, y).isTransparent())
                     && GP.world.hasBackAt(x, y)) {
                 spriter.draw(GP.world.getBackMapBlock(x, y).getTex(), drawX(x), drawY(y));
-                if (!GP.world.hasForeAt(x, y) && x == GP.curX && y == GP.curY)
-                    drawWreck(GP.world.getBackMap(GP.curX, GP.curY));
+                if (!GP.world.hasForeAt(x, y) && x == GP.input.getCurX() && y == GP.input.getCurY())
+                    drawWreck(GP.world.getBackMap(GP.input.getCurX(), GP.input.getCurY()));
             }
         }
         if (GP.world.hasForeAt(x, y) && GP.world.getForeMapBlock(x, y).isBackground() == drawBG) {
             spriter.draw(GP.world.getForeMapBlock(x, y).getTex(), drawX(x), drawY(y));
-            if (x == GP.curX && y == GP.curY)
-                drawWreck(GP.world.getForeMap(GP.curX, GP.curY));
+            if (x == GP.input.getCurX() && y == GP.input.getCurY())
+                drawWreck(GP.world.getForeMap(GP.input.getCurX(), GP.input.getCurY()));
         }
     }
 
@@ -111,17 +111,17 @@ public class GameRenderer extends Renderer {
         float y = getHeight() / 2 - (float) creative.getRegionHeight() / 2;
         spriter.draw(creative, x, y);
         spriter.draw(textureRegions.get("handle"), x + 156,
-                y + 18 + (GP.creativeScroll * (72f / GameProc.MAX_CREATIVE_SCROLL)));
-        for (int i = GP.creativeScroll * 8; i < GP.creativeScroll * 8 + 40; i++) {
+                y + 18 + (GP.input.getCreativeScroll() * (72f / GameProc.MAX_CREATIVE_SCROLL)));
+        for (int i = GP.input.getCreativeScroll() * 8; i < GP.input.getCreativeScroll() * 8 + 40; i++) {
             if (i > 0 && i < GameItems.getItemsSize())
                 if (GameItems.getItem(i).isBlock()) {
                     spriter.draw(GameItems.getBlock(GameItems.getBlockIdByItemId(i)).getTex(),
-                            x + 8 + ((i - GP.creativeScroll * 8) % 8) * 18,
-                            y + 18 + ((i - GP.creativeScroll * 8) / 8) * 18);
+                            x + 8 + ((i - GP.input.getCreativeScroll() * 8) % 8) * 18,
+                            y + 18 + ((i - GP.input.getCreativeScroll() * 8) / 8) * 18);
                 } else {
                     spriter.draw(GameItems.getItem(i).getTex(),
-                            x + 8 + ((i - GP.creativeScroll * 8) % 8) * 18,
-                            y + 18 + ((i - GP.creativeScroll * 8) / 8) * 18);
+                            x + 8 + ((i - GP.input.getCreativeScroll() * 8) % 8) * 18,
+                            y + 18 + ((i - GP.input.getCreativeScroll() * 8) / 8) * 18);
                 }
         }
         for (int i = 0; i < 9; i++) {
@@ -142,13 +142,13 @@ public class GameRenderer extends Renderer {
         TextureRegion hotbar = textureRegions.get("hotbar");
         TextureRegion hotbarSelector = textureRegions.get("hotbar_selector");
 
-        if (GP.world.hasForeAt(GP.curX, GP.curY) ||
-                GP.world.hasBackAt(GP.curX, GP.curY) ||
+        if (GP.world.hasForeAt(GP.input.getCurX(), GP.input.getCurY()) ||
+                GP.world.hasBackAt(GP.input.getCurX(), GP.input.getCurY()) ||
                 GP.controlMode == ControlMode.CURSOR ||
                 !CaveGame.TOUCH)
             spriter.draw(cursor,
-                    GP.curX * 16 - getCamX(),
-                    GP.curY * 16 - getCamY());
+                    GP.input.getCurX() * 16 - getCamX(),
+                    GP.input.getCurY() * 16 - getCamY());
         spriter.draw(hotbar, getWidth() / 2 - (float) hotbar.getRegionWidth() / 2, 0);
         for (int i = 0; i < 9; i++) {
             if (GP.player.inventory[i] > 0) {
@@ -241,11 +241,11 @@ public class GameRenderer extends Renderer {
             drawString("FPS: " + GameScreen.FPS, 0, 0);
             drawString("X: " + (int) (GP.player.pos.x / 16), 0, 10);
             drawString("Y: " + (int) (GP.player.pos.y / 16), 0, 20);
-            drawString("CurX: " + GP.curX, 0, 30);
-            drawString("CurY: " + GP.curY, 0, 40);
+            drawString("CurX: " + GP.input.getCurX(), 0, 30);
+            drawString("CurY: " + GP.input.getCurY(), 0, 40);
             drawString("Mobs: " + GP.mobs.size(), 0, 50);
             drawString("Drops: " + GP.drops.size(), 0, 60);
-            drawString("Block: " + GameItems.getBlockKey(GP.world.getForeMap(GP.curX, GP.curY)), 0, 70);
+            drawString("Block: " + GameItems.getBlockKey(GP.world.getForeMap(GP.input.getCurX(), GP.input.getCurY())), 0, 70);
             drawString("Hand: " + GameItems.getItemKey(GP.player.inventory[GP.player.slot]), 0, 80);
             drawString("Game mode: " + GP.player.gameMode, 0, 90);
             spriter.end();
index 0d796b8b3a22583ed5e7e540bcb3b0ebe5bfe6a0..49822863f876b074fe28f25e10aab9a376951aab 100644 (file)
@@ -81,7 +81,7 @@ public class GameSaver {
                     loadMap(Gdx.files.absolute(CaveGame.GAME_FOLDER + "/saves/backmap.sav"))
             );
             gameProc.physics = new GamePhysics();
-            gameProc.resetRenderer();
+            gameProc.input = new GameInput();
         } catch (Exception e) {
             Gdx.app.error("GameSaver", e.getMessage(), e);
             Gdx.app.exit();
index 9ba00bcfca9ee5e393cb188651ed18b355bd23d7..31e6dd06919aa20cf1ca70e5ba2cc89d93c0e2ec 100644 (file)
@@ -7,7 +7,6 @@ import com.badlogic.gdx.math.Rectangle;
 import com.badlogic.gdx.utils.JsonValue;
 import ru.deadsoftware.cavedroid.CaveGame;
 import ru.deadsoftware.cavedroid.GameScreen;
-import ru.deadsoftware.cavedroid.game.GameInput;
 
 import static ru.deadsoftware.cavedroid.GameScreen.GP;
 
@@ -22,10 +21,7 @@ public class InputHandlerGame extends InputAdapter {
             LMB = 5,
             RMB = 6;
 
-    private GameInput gameInput;
-
     public InputHandlerGame() {
-        this.gameInput = new GameInput();
         loadTouchButtonsFromJSON();
     }
 
@@ -62,13 +58,13 @@ public class InputHandlerGame extends InputAdapter {
 
     @Override
     public boolean keyDown(int keycode) {
-        gameInput.keyDown(keycode);
+        GP.input.keyDown(keycode);
         return false;
     }
 
     @Override
     public boolean keyUp(int keycode) {
-        gameInput.keyUp(keycode);
+        GP.input.keyUp(keycode);
         return false;
     }
 
@@ -81,31 +77,31 @@ public class InputHandlerGame extends InputAdapter {
             int touchedKey = getTouchedKey(touchX, touchY);
             switch (touchedKey) {
                 case UP:
-                    gameInput.keyDown(GP.controlMode == ControlMode.CURSOR ? Input.Keys.W : Input.Keys.SPACE);
+                    GP.input.keyDown(GP.controlMode == ControlMode.CURSOR ? Input.Keys.W : Input.Keys.SPACE);
                     break;
                 case DOWN:
-                    gameInput.keyDown(GP.controlMode == ControlMode.CURSOR ? Input.Keys.S : Input.Keys.CONTROL_LEFT);
+                    GP.input.keyDown(GP.controlMode == ControlMode.CURSOR ? Input.Keys.S : Input.Keys.CONTROL_LEFT);
                     break;
                 case LEFT:
-                    gameInput.keyDown(Input.Keys.A);
+                    GP.input.keyDown(Input.Keys.A);
                     break;
                 case RIGHT:
-                    gameInput.keyDown(Input.Keys.D);
+                    GP.input.keyDown(Input.Keys.D);
                     break;
                 case ALT:
-                    gameInput.keyDown(Input.Keys.ALT_LEFT);
+                    GP.input.keyDown(Input.Keys.ALT_LEFT);
                     break;
                 case LMB:
-                    gameInput.touchDown(touchX, touchY, Input.Buttons.LEFT);
+                    GP.input.touchDown(touchX, touchY, Input.Buttons.LEFT);
                     break;
                 case RMB:
-                    gameInput.touchDown(touchX, touchY, Input.Buttons.RIGHT);
+                    GP.input.touchDown(touchX, touchY, Input.Buttons.RIGHT);
                     break;
                 default:
-                    gameInput.touchDown(touchX, touchY, touchedKey);
+                    GP.input.touchDown(touchX, touchY, touchedKey);
             }
         } else {
-            gameInput.touchDown(touchX, touchY, button);
+            GP.input.touchDown(touchX, touchY, button);
         }
         return false;
     }
@@ -123,19 +119,19 @@ public class InputHandlerGame extends InputAdapter {
                 case LEFT:
                 case RIGHT:
                 case ALT:
-                    gameInput.keyUp(GP.keyDownCode);
+                    GP.input.keyUp(GP.input.getKeyDownCode());
                     break;
                 case LMB:
-                    gameInput.touchUp(touchX, touchY, Input.Buttons.LEFT);
+                    GP.input.touchUp(touchX, touchY, Input.Buttons.LEFT);
                     break;
                 case RMB:
-                    gameInput.touchUp(touchX, touchY, Input.Buttons.RIGHT);
+                    GP.input.touchUp(touchX, touchY, Input.Buttons.RIGHT);
                     break;
                 default:
-                    gameInput.touchUp(touchX, touchY, touchedKey);
+                    GP.input.touchUp(touchX, touchY, touchedKey);
             }
         } else {
-            gameInput.touchUp(touchX, touchY, button);
+            GP.input.touchUp(touchX, touchY, button);
         }
         return false;
     }
@@ -144,19 +140,19 @@ public class InputHandlerGame extends InputAdapter {
     public boolean touchDragged(int screenX, int screenY, int pointer) {
         float touchX = transformScreenX(screenX);
         float touchY = transformScreenY(screenY);
-        if (CaveGame.TOUCH && GP.isKeyDown) {
+        if (CaveGame.TOUCH && GP.input.isKeyDown()) {
             if (getTouchedKey(touchX, touchY) == -1) {
-                gameInput.keyUp(GP.keyDownCode);
+                GP.input.keyUp(GP.input.getKeyDownCode());
             }
         } else {
-            gameInput.touchDragged(touchX, touchY);
+            GP.input.touchDragged(touchX, touchY);
         }
         return false;
     }
 
     @Override
     public boolean scrolled(int amount) {
-        gameInput.scrolled(amount);
+        GP.input.scrolled(amount);
         return false;
     }
 }