DEADSOFTWARE

Refactor
authorfred-boy <fredboy@protonmail.com>
Sat, 28 Sep 2019 15:08:41 +0000 (22:08 +0700)
committerfred-boy <fredboy@protonmail.com>
Sun, 29 Sep 2019 04:39:18 +0000 (11:39 +0700)
Rewrite input handling
Move textures to json

13 files changed:
android/assets/json/game_items.json [new file with mode: 0644]
android/assets/json/texture_regions.json [new file with mode: 0644]
android/assets/json/touch_buttons.json [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/GameScreen.java
core/src/ru/deadsoftware/cavedroid/game/GameInput.java
core/src/ru/deadsoftware/cavedroid/game/GameItems.java
core/src/ru/deadsoftware/cavedroid/game/GameProc.java
core/src/ru/deadsoftware/cavedroid/game/GameRenderer.java
core/src/ru/deadsoftware/cavedroid/game/objects/Player.java
core/src/ru/deadsoftware/cavedroid/menu/MenuRenderer.java
core/src/ru/deadsoftware/cavedroid/misc/Assets.java
core/src/ru/deadsoftware/cavedroid/misc/InputHandlerGame.java
core/src/ru/deadsoftware/cavedroid/misc/Renderer.java

diff --git a/android/assets/json/game_items.json b/android/assets/json/game_items.json
new file mode 100644 (file)
index 0000000..12cad82
--- /dev/null
@@ -0,0 +1,610 @@
+{
+  "blocks": {
+    "none": {
+      "collision": false,
+      "transparent": true
+    },
+    "stone": {
+      "hp": 450,
+      "drop": "cobblestone"
+    },
+    "grass": {
+      "hp": 54,
+      "drop": "dirt"
+    },
+    "dirt": {
+      "hp": 45
+    },
+    "cobblestone": {
+      "hp": 600
+    },
+    "planks": {
+      "hp": 180
+    },
+    "sapling": {
+      "hp": 0,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "block_required": true
+    },
+    "bedrock": {
+      "hp": -1
+    },
+    "water": {
+      "hp": -1,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "fluid": true,
+      "meta": "water"
+    },
+    "lava": {
+      "hp": -1,
+      "collision": false,
+      "background": false,
+      "fluid": true,
+      "meta": "lava"
+    },
+    "sand": {
+      "hp": 45
+    },
+    "gravel": {
+      "hp": 54
+    },
+    "gold_ore": {
+      "hp": 900
+    },
+    "iron_ore": {
+      "hp": 900
+    },
+    "coal_ore": {
+      "hp": 900,
+      "drop": "coal"
+    },
+    "log": {
+      "hp": 180
+    },
+    "leaves": {
+      "hp": 21
+    },
+    "sponge": {
+      "hp": 54
+    },
+    "glass": {
+      "hp": 27,
+      "drop": "none",
+      "background": false,
+      "transparent": true
+    },
+    "lapis_ore": {
+      "hp": 900,
+      "drop": "lapis"
+    },
+    "lapis_block": {
+      "hp": 900
+    },
+    "sandstone": {
+      "hp": 240
+    },
+    "noteblock": {
+      "hp": 75
+    },
+    "bed_l": {
+      "hp": 21,
+      "drop": "none",
+      "collision": false,
+      "background": true,
+      "transparent": true
+    },
+    "bed_r": {
+      "hp": 21,
+      "drop": "none",
+      "collision": false,
+      "background": true,
+      "transparent": true
+    },
+    "web": {
+      "hp": 1200,
+      "collision": false,
+      "background": false,
+      "transparent": true
+    },
+    "tallgrass": {
+      "hp": 0,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "block_required": true
+    },
+    "deadbush": {
+      "hp": 0,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "block_required": true
+    },
+    "bricks": {
+      "hp": 600
+    },
+    "dandelion": {
+      "hp": 0,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "block_required": true
+    },
+    "rose": {
+      "hp": 0,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "block_required": true
+    },
+    "mushroom_brown": {
+      "hp": 0,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "block_required": true
+    },
+    "mushroom_red": {
+      "hp": 0,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "block_required": true
+    },
+    "wool": {
+      "hp": 75
+    },
+    "wool_orange": {
+      "hp": 75
+    },
+    "wool_magenta": {
+      "hp": 75
+    },
+    "wool_lightblue": {
+      "hp": 75
+    },
+    "wool_yellow": {
+      "hp": 75
+    },
+    "wool_lime": {
+      "hp": 75
+    },
+    "wool_pink": {
+      "hp": 75
+    },
+    "wool_gray": {
+      "hp": 75
+    },
+    "wool_lightgray": {
+      "hp": 75
+    },
+    "wool_cyan": {
+      "hp": 75
+    },
+    "wool_purple": {
+      "hp": 75
+    },
+    "wool_blue": {
+      "hp": 75
+    },
+    "wool_brown": {
+      "hp": 75
+    },
+    "wool_green": {
+      "hp": 75
+    },
+    "wool_red": {
+      "hp": 75
+    },
+    "wool_black": {
+      "hp": 75
+    },
+    "gold_block": {
+      "hp": 900
+    },
+    "iron_block": {
+      "hp": 1500
+    },
+    "stone_slab": {
+      "top": 8,
+      "hp": 600,
+      "transparent": true
+    },
+    "double_stone_slab": {
+      "hp": 600,
+      "drop": "stone_slab"
+    },
+    "sandstone_slab": {
+      "top": 8,
+      "hp": 600,
+      "transparent": true
+    },
+    "wooden_slab": {
+      "top": 8,
+      "hp": 180,
+      "transparent": true
+    },
+    "cobblestone_slab": {
+      "top": 8,
+      "hp": 600,
+      "transparent": true
+    },
+    "brick_slab": {
+      "top": 8,
+      "hp": 600,
+      "transparent": true
+    },
+    "stonebrick": {
+      "hp": 450
+    },
+    "stonebrick_slab": {
+      "top": 8,
+      "hp": 450,
+      "transparent": true
+    },
+    "cactus": {
+      "left": 1,
+      "right": 1,
+      "hp": 39,
+      "transparent": true,
+      "block_required": true
+    },
+    "water_16": {
+      "hp": -1,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "texture": "water",
+      "fluid": true,
+      "meta": "water"
+    },
+    "water_12": {
+      "hp": -1,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "fluid": true,
+      "meta": "water"
+    },
+    "water_8": {
+      "hp": -1,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "fluid": true,
+      "meta": "water"
+    },
+    "water_4": {
+      "hp": -1,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "fluid": true,
+      "meta": "water"
+    },
+    "lava_16": {
+      "hp": -1,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "texture": "lava",
+      "fluid": true,
+      "meta": "lava"
+    },
+    "lava_12": {
+      "hp": -1,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "fluid": true,
+      "meta": "lava"
+    },
+    "lava_8": {
+      "hp": -1,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "fluid": true,
+      "meta": "lava"
+    },
+    "lava_4": {
+      "hp": -1,
+      "collision": false,
+      "background": false,
+      "transparent": true,
+      "fluid": true,
+      "meta": "lava"
+    },
+    "obsidian": {
+      "hp": 1500
+    }
+  },
+  "items": {
+    "none": {
+      "name": "",
+      "type": "block"
+    },
+    "stone": {
+      "name": "Stone",
+      "type": "block"
+    },
+    "grass": {
+      "name": "Grass",
+      "type": "block"
+    },
+    "dirt": {
+      "name": "Dirt",
+      "type": "block"
+    },
+    "cobblestone": {
+      "name": "Cobblestone",
+      "type": "block"
+    },
+    "planks": {
+      "name": "Planks",
+      "type": "block"
+    },
+    "sapling": {
+      "name": "Sapling",
+      "type": "block"
+    },
+    "bedrock": {
+      "name": "Bedrock",
+      "type": "block"
+    },
+    "water": {
+      "name": "Water",
+      "type": "block"
+    },
+    "lava": {
+      "name": "Lava",
+      "type": "block"
+    },
+    "sand": {
+      "name": "Sand",
+      "type": "block"
+    },
+    "gravel": {
+      "name": "Gravel",
+      "type": "block"
+    },
+    "gold_ore": {
+      "name": "Golden Ore",
+      "type": "block"
+    },
+    "iron_ore": {
+      "name": "Iron Ore",
+      "type": "block"
+    },
+    "coal_ore": {
+      "name": "Coal Ore",
+      "type": "block"
+    },
+    "log": {
+      "name": "Wood",
+      "type": "block"
+    },
+    "leaves": {
+      "name": "Leaves",
+      "type": "block"
+    },
+    "glass": {
+      "name": "Glass",
+      "type": "block"
+    },
+    "lapis_ore": {
+      "name": "Lapis Ore",
+      "type": "block"
+    },
+    "lapis_block": {
+      "name": "Lapis Block",
+      "type": "block"
+    },
+    "sandstone": {
+      "name": "Sandstone",
+      "type": "block"
+    },
+    "web": {
+      "name": "Cobweb",
+      "type": "block"
+    },
+    "tallgrass": {
+      "name": "Tall Grass",
+      "type": "block"
+    },
+    "deadbush": {
+      "name": "Dead Bush",
+      "type": "block"
+    },
+    "bricks": {
+      "name": "Bricks",
+      "type": "block"
+    },
+    "dandelion": {
+      "name": "Dandelion",
+      "type": "block"
+    },
+    "rose": {
+      "name": "Rose",
+      "type": "block"
+    },
+    "mushroom_brown": {
+      "name": "Mushroom",
+      "type": "block"
+    },
+    "mushroom_red": {
+      "name": "Mushroom",
+      "type": "block"
+    },
+    "wool": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_orange": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_magenta": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_lightblue": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_yellow": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_lime": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_pink": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_gray": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_lightgray": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_cyan": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_purple": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_blue": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_brown": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_green": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_red": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "wool_black": {
+      "name": "Wool",
+      "type": "block"
+    },
+    "gold_block": {
+      "name": "Gold Block",
+      "type": "block"
+    },
+    "iron_block": {
+      "name": "Iron Block",
+      "type": "block"
+    },
+    "stone_slab": {
+      "name": "Stone Slab",
+      "type": "block",
+      "meta": "slab"
+    },
+    "sandstone_slab": {
+      "name": "Sandstone Slab",
+      "type": "block",
+      "meta": "slab"
+    },
+    "wooden_slab": {
+      "name": "Wooden Slab",
+      "type": "block",
+      "meta": "slab"
+    },
+    "cobblestone_slab": {
+      "name": "Cobblestone Slab",
+      "type": "block",
+      "meta": "slab"
+    },
+    "brick_slab": {
+      "name": "Brick Slab",
+      "type": "block",
+      "meta": "slab"
+    },
+    "stonebrick": {
+      "name": "Stone Brick",
+      "type": "block"
+    },
+    "stonebrick_slab": {
+      "name": "Stone Brick Slab",
+      "type": "block",
+      "meta": "slab"
+    },
+    "cactus": {
+      "name": "Cactus",
+      "type": "block"
+    },
+    "obsidian": {
+      "name": "Obsidian",
+      "type": "block"
+    },
+    "wood_sword": {
+      "name": "Wooden Sword",
+      "type": "tool"
+    },
+    "stone_sword": {
+      "name": "Stone Sword",
+      "type": "tool"
+    },
+    "iron_sword": {
+      "name": "Iron Sword",
+      "type": "tool"
+    },
+    "diamond_sword": {
+      "name": "Diamond Sword",
+      "type": "tool"
+    },
+    "gold_sword": {
+      "name": "Golden Sword",
+      "type": "tool"
+    },
+    "wood_shovel": {
+      "name": "Wooden Shovel",
+      "type": "tool"
+    },
+    "stone_shovel": {
+      "name": "Stone Shovel",
+      "type": "tool"
+    },
+    "iron_shovel": {
+      "name": "Iron Shovel",
+      "type": "tool"
+    },
+    "diamond_shovel": {
+      "name": "Diamond Shovel",
+      "type": "tool"
+    },
+    "gold_shovel": {
+      "name": "Golden Shovel",
+      "type": "tool"
+    },
+    "bucket_empty": {
+      "name": "Empty Bucket",
+      "type": "tool"
+    },
+    "bucket_water": {
+      "name": "Water Bucket",
+      "type": "tool"
+    },
+    "bucket_lava": {
+      "name": "Lava Bucket",
+      "type": "tool"
+    }
+  }
+}
\ No newline at end of file
diff --git a/android/assets/json/texture_regions.json b/android/assets/json/texture_regions.json
new file mode 100644 (file)
index 0000000..d032497
--- /dev/null
@@ -0,0 +1,141 @@
+{
+  "touch_gui": {
+    "up": {
+      "w": 26,
+      "h": 26
+    },
+    "down": {
+      "x": 52,
+      "w": 26,
+      "h": 26
+    },
+    "left": {
+      "x": 26,
+      "w": 26,
+      "h": 26
+    },
+    "right": {
+      "x": 78,
+      "w": 26,
+      "h": 26
+    },
+    "lmb": {
+      "y": 26,
+      "w": 26,
+      "h": 26
+    },
+    "alt": {
+      "x": 26,
+      "y": 26,
+      "w": 26,
+      "h": 26
+    },
+    "rmb": {
+      "x": 52,
+      "y": 26,
+      "w": 26,
+      "h": 26
+    }
+  },
+  "break": {
+    "break_0": {
+      "w": 16,
+      "h": 16
+    },
+    "break_1": {
+      "x": 16,
+      "w": 16,
+      "h": 16
+    },
+    "break_2": {
+      "x": 32,
+      "w": 16,
+      "h": 16
+    },
+    "break_3": {
+      "x": 48,
+      "w": 16,
+      "h": 16
+    },
+    "break_4": {
+      "x": 64,
+      "w": 16,
+      "h": 16
+    },
+    "break_5": {
+      "x": 80,
+      "w": 16,
+      "h": 16
+    },
+    "break_6": {
+      "x": 96,
+      "w": 16,
+      "h": 16
+    },
+    "break_7": {
+      "x": 112,
+      "w": 16,
+      "h": 16
+    },
+    "break_8": {
+      "x": 128,
+      "w": 16,
+      "h": 16
+    },
+    "break_9": {
+      "x": 144,
+      "w": 16,
+      "h": 16
+    }
+  },
+  "allitems": {
+    "creative": {
+      "w": 176,
+      "h": 136
+    },
+    "handle": {
+      "x": 3,
+      "y": 137,
+      "w": 12,
+      "h": 15
+    }
+  },
+  "buttons": {
+    "button_0": {
+      "w": 200,
+      "h": 20
+    },
+    "button_1": {
+      "y": 20,
+      "w": 200,
+      "h": 20
+    },
+    "button_2": {
+      "y": 40,
+      "w": 200,
+      "h": 20
+    }
+  },
+  "gui": {
+    "hotbar": {
+      "y": 16,
+      "w": 182,
+      "h": 22
+    },
+    "hotbar_selector": {
+      "y": 38,
+      "w": 24,
+      "h": 24
+    },
+    "cursor": {
+      "w": 16,
+      "h": 16
+    }
+  },
+  "shade": {
+    "shade": {}
+  },
+  "gamelogo": {
+    "gamelogo": {}
+  }
+}
\ No newline at end of file
diff --git a/android/assets/json/touch_buttons.json b/android/assets/json/touch_buttons.json
new file mode 100644 (file)
index 0000000..ef5c42e
--- /dev/null
@@ -0,0 +1,44 @@
+{
+  "up": {
+    "x": 26,
+    "y": -52,
+    "w": 26,
+    "h": 26
+  },
+  "down": {
+    "x": 26,
+    "y": -26,
+    "w": 26,
+    "h": 26
+  },
+  "left": {
+    "x": 0,
+    "y": -26,
+    "w": 26,
+    "h": 26
+  },
+  "right": {
+    "x": 52,
+    "y": -26,
+    "w": 26,
+    "h": 26
+  },
+  "alt": {
+    "x": 78,
+    "y": -26,
+    "w": 26,
+    "h": 26
+  },
+  "lmb": {
+    "x": -52,
+    "y": -26,
+    "w": 26,
+    "h": 26
+  },
+  "rmb": {
+    "x": -26,
+    "y": -26,
+    "w": 26,
+    "h": 26
+  }
+}
\ No newline at end of file
index f741dbd62e06c8511c430043bc3eaa9b5bf61090..fc82bf28ca1544a0b30e916c9d5166e946c49341 100644 (file)
@@ -6,7 +6,10 @@ import ru.deadsoftware.cavedroid.game.GameItems;
 import ru.deadsoftware.cavedroid.game.GameProc;
 import ru.deadsoftware.cavedroid.game.GameSaver;
 import ru.deadsoftware.cavedroid.menu.MenuRenderer;
-import ru.deadsoftware.cavedroid.misc.*;
+import ru.deadsoftware.cavedroid.misc.Assets;
+import ru.deadsoftware.cavedroid.misc.InputHandlerGame;
+import ru.deadsoftware.cavedroid.misc.InputHandlerMenu;
+import ru.deadsoftware.cavedroid.misc.Renderer;
 import ru.deadsoftware.cavedroid.misc.states.AppState;
 import ru.deadsoftware.cavedroid.misc.states.GameState;
 import ru.deadsoftware.cavedroid.misc.states.MenuState;
@@ -14,21 +17,24 @@ import ru.deadsoftware.cavedroid.misc.states.MenuState;
 public class GameScreen implements Screen {
 
     public static GameProc GP;
-    public static Renderer RENDERER;
 
     public static int FPS;
-    public static boolean SHOW_DEBUG = true;
+    public static boolean SHOW_DEBUG = false;
     public static boolean SHOW_MAP = false;
-    public static int NEW_GAME_MODE = 0;
 
+    private Renderer renderer;
     private MenuRenderer menuRenderer;
 
+    private InputHandlerGame inputHandlerGame;
+    private InputHandlerMenu inputHandlerMenu;
+
     public GameScreen() {
         Assets.load();
         GameItems.load();
         menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480);
-        RENDERER = menuRenderer;
-        Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer));
+        inputHandlerMenu = new InputHandlerMenu(menuRenderer);
+        renderer = menuRenderer;
+        Gdx.input.setInputProcessor(inputHandlerMenu);
     }
 
     public static float getWidth() {
@@ -63,10 +69,12 @@ public class GameScreen implements Screen {
                 break;
 
             case LOAD:
-                GP = GameSaver.load();
                 GP.resetRenderer();
-                RENDERER = GP.renderer;
-                Gdx.input.setInputProcessor(new InputHandlerGame());
+                renderer = GP.renderer;
+                if (inputHandlerGame == null) {
+                    inputHandlerGame = new InputHandlerGame();
+                }
+                Gdx.input.setInputProcessor(inputHandlerGame);
                 CaveGame.APP_STATE = AppState.GAME;
                 CaveGame.GAME_STATE = GameState.PLAY;
                 break;
@@ -76,12 +84,11 @@ public class GameScreen implements Screen {
                 CaveGame.APP_STATE = AppState.MENU;
                 CaveGame.MENU_STATE = MenuState.MAIN;
                 GP.dispose();
-                menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480);
-                RENDERER = menuRenderer;
-                Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer));
+                renderer = menuRenderer;
+                Gdx.input.setInputProcessor(inputHandlerMenu);
                 break;
         }
-        RENDERER.render();
+        renderer.render();
     }
 
     @Override
@@ -89,12 +96,12 @@ public class GameScreen implements Screen {
         switch (CaveGame.APP_STATE) {
             case MENU:
                 menuRenderer = new MenuRenderer(CaveGame.TOUCH ? 320 : 480);
-                Gdx.input.setInputProcessor(new InputHandlerMenu(menuRenderer));
-                RENDERER = menuRenderer;
+                Gdx.input.setInputProcessor(inputHandlerMenu);
+                renderer = menuRenderer;
                 break;
             case GAME:
                 GP.resetRenderer();
-                RENDERER = GP.renderer;
+                renderer = GP.renderer;
                 break;
         }
     }
index 13b2fbf4638b4dbbdbfacd0204b3de39144e974d..32672ed2ca3223a8efc9846999816e6cf56aee77 100644 (file)
@@ -1,13 +1,14 @@
 package ru.deadsoftware.cavedroid.game;
 
 import com.badlogic.gdx.Input;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
 import com.badlogic.gdx.utils.TimeUtils;
 import ru.deadsoftware.cavedroid.CaveGame;
 import ru.deadsoftware.cavedroid.GameScreen;
 import ru.deadsoftware.cavedroid.game.mobs.Pig;
+import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.ControlMode;
 import ru.deadsoftware.cavedroid.misc.states.AppState;
-import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.states.GameState;
 
 import static ru.deadsoftware.cavedroid.GameScreen.GP;
@@ -18,11 +19,13 @@ public class GameInput {
         return GameItems.isFluid(GP.world.getForeMap(GP.player.getMapX(), GP.player.getLowerMapY()));
     }
 
-    private boolean insideCreativeInv(int screenX, int screenY) {
-        return (screenX > GP.renderer.getWidth() / 2 - Assets.creativeInv.getRegionWidth() / 2 &&
-                screenX < GP.renderer.getWidth() / 2 + Assets.creativeInv.getRegionWidth() / 2 &&
-                screenY > GP.renderer.getHeight() / 2 - Assets.creativeInv.getRegionHeight() / 2 &&
-                screenY < GP.renderer.getHeight() / 2 + Assets.creativeInv.getRegionHeight() / 2);
+    @SuppressWarnings("IntegerDivisionInFloatingPointContext")
+    private boolean insideCreativeInv(float screenX, float screenY) {
+        TextureRegion creative = Assets.textureRegions.get("creative");
+        return (screenX > GP.renderer.getWidth() / 2 - creative.getRegionWidth() / 2 &&
+                screenX < GP.renderer.getWidth() / 2 + creative.getRegionWidth() / 2 &&
+                screenY > GP.renderer.getHeight() / 2 - creative.getRegionHeight() / 2 &&
+                screenY < GP.renderer.getHeight() / 2 + creative.getRegionHeight() / 2);
     }
 
     private void wasdPressed(int keycode) {
@@ -143,23 +146,25 @@ public class GameInput {
         }
     }
 
-    public void touchDown(int screenX, int screenY, int button) {
+    public void touchDown(float touchX, float touchY, int button) {
         GP.touchDownTime = TimeUtils.millis();
         GP.isTouchDown = true;
         GP.touchDownBtn = button;
-        GP.touchDownX = screenX;
-        GP.touchDownY = screenY;
+        GP.touchDownX = touchX;
+        GP.touchDownY = touchY;
     }
 
-    public void touchUp(int screenX, int screenY, int button) {
+    public void touchUp(float screenX, float screenY, int button) {
         if (CaveGame.TOUCH && GP.isKeyDown) {
             keyUp(GP.keyDownCode);
             GP.isKeyDown = false;
         }
+        TextureRegion hotbar = Assets.textureRegions.get("hotbar");
+        TextureRegion creative = Assets.textureRegions.get("creative");
         if (GP.isTouchDown) {
             if (CaveGame.GAME_STATE == GameState.CREATIVE_INV && insideCreativeInv(screenX, screenY)) {
-                int ix = (int) (screenX - (GP.renderer.getWidth() / 2 - Assets.creativeInv.getRegionWidth() / 2 + 8)) / 18;
-                int iy = (int) (screenY - (GP.renderer.getHeight() / 2 - Assets.creativeInv.getRegionHeight() / 2 + 18)) / 18;
+                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);
                 if (ix >= 8 || ix < 0 || iy < 0 || iy >= 5) item = -1;
                 if (item >= 0 && item < GameItems.getItemsSize()) {
@@ -168,10 +173,10 @@ public class GameInput {
                 }
             } else if (CaveGame.GAME_STATE == GameState.CREATIVE_INV) {
                 CaveGame.GAME_STATE = GameState.PLAY;
-            } else if (screenY < Assets.invBar.getRegionHeight() &&
-                    screenX > GP.renderer.getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 &&
-                    screenX < GP.renderer.getWidth() / 2 + (float) Assets.invBar.getRegionWidth() / 2) {
-                GP.player.slot = (int) ((screenX - (GP.renderer.getWidth() / 2 - Assets.invBar.getRegionWidth() / 2)) / 20);
+            } else if (screenY < hotbar.getRegionHeight() &&
+                    screenX > GP.renderer.getWidth() / 2 - (float) hotbar.getRegionWidth() / 2 &&
+                    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,
                         GP.player.inventory[GP.player.slot], false);
@@ -182,7 +187,7 @@ public class GameInput {
         GP.isTouchDown = false;
     }
 
-    public void touchDragged(int screenX, int screenY) {
+    public void touchDragged(float screenX, float screenY) {
         if (CaveGame.GAME_STATE == GameState.CREATIVE_INV && Math.abs(screenY - GP.touchDownY) > 16) {
             if (insideCreativeInv(screenX, screenY)) {
                 GP.creativeScroll -= (screenY - GP.touchDownY) / 16;
index da430773336efa771a35be542ad0bae8efcb3883..82c4b33264acb0942f27968f0e996707328a06d1 100644 (file)
@@ -4,10 +4,10 @@ import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.graphics.Texture;
 import com.badlogic.gdx.graphics.g2d.Sprite;
 import com.badlogic.gdx.utils.ArrayMap;
-import com.badlogic.gdx.utils.JsonReader;
 import com.badlogic.gdx.utils.JsonValue;
 import ru.deadsoftware.cavedroid.game.objects.Block;
 import ru.deadsoftware.cavedroid.game.objects.Item;
+import ru.deadsoftware.cavedroid.misc.Assets;
 
 import java.util.HashMap;
 
@@ -19,87 +19,85 @@ public class GameItems {
     private static ArrayMap<String, Block> blocks = new ArrayMap<>();
     private static ArrayMap<String, Item> items = new ArrayMap<>();
 
-    public static boolean isFluid(int id) {
+    static boolean isFluid(int id) {
         return getBlock(id).isFluid();
     }
 
-    public static boolean isWater(int id) {
+    static boolean isWater(int id) {
         return getBlock(id).getMeta().equals("water");
     }
 
-    public static boolean isLava(int id) {
+    static boolean isLava(int id) {
         return getBlock(id).getMeta().equals("lava");
     }
 
-    public static boolean isSlab(int id) {
+    static boolean isSlab(int id) {
         return getBlock(id).getMeta().equals("slab");
     }
 
-    public static boolean fluidCanFlowThere(int thisId, int thatId) {
+    static boolean fluidCanFlowThere(int thisId, int thatId) {
         return thatId == 0 || (!getBlock(thatId).hasCollision() && !isFluid(thatId)) ||
                 (isWater(thisId) && isWater(thatId) && thisId < thatId) ||
                 (isLava(thisId) && isLava(thatId) && thisId < thatId);
     }
 
-    public static Block getBlock(int id) {
+    static Block getBlock(int id) {
         return blocks.getValueAt(id);
     }
 
-    public static Item getItem(int id) {
+    static Item getItem(int id) {
         return items.getValueAt(id);
     }
 
-    public static Block getBlock(String key) {
+    static Block getBlock(String key) {
         return blocks.getValueAt(blocksIds.get(key));
     }
 
-    public static Item getItem(String key) {
+    static Item getItem(String key) {
         return items.getValueAt(itemsIds.get(key));
     }
 
-    public static int getBlockId(String key) {
+    static int getBlockId(String key) {
         return blocksIds.get(key);
     }
 
-    public static int getItemId(String key) {
+    static int getItemId(String key) {
         return itemsIds.get(key);
     }
 
-    public static String getBlockKey(int id) {
+    static String getBlockKey(int id) {
         return blocks.getKeyAt(id);
     }
 
-    public static String getItemKey(int id) {
+    static String getItemKey(int id) {
         return items.getKeyAt(id);
     }
 
-    public static int getBlockIdByItemId(int id) {
+    static int getBlockIdByItemId(int id) {
         return getBlockId(items.getKeyAt(id));
     }
 
-    public static int getBlocksSize() {
+    static int getBlocksSize() {
         return blocks.size;
     }
 
-    public static int getItemsSize() {
+    static int getItemsSize() {
         return items.size;
     }
 
-    public static Sprite getBlockTex(int id) {
+    static Sprite getBlockTex(int id) {
         return getBlock(id).getTex();
     }
 
-    public static Sprite getItemTex(int id) {
+    static Sprite getItemTex(int id) {
         if (items.getValueAt(id).getType().equals("block")) return getBlockTex(id);
         else return getItem(id).getTex();
     }
 
     public static void load() {
-        JsonValue json = new JsonReader().parse(Gdx.files.internal("game_items.json"));
-        JsonValue block = json.child.child;
-        JsonValue item = json.child.next.child;
-        while (block != null) {
-            String key = block.name;
+        JsonValue json = Assets.jsonReader.parse(Gdx.files.internal("json/game_items.json"));
+        for (JsonValue block = json.get("blocks").child(); block != null; block = block.next()) {
+            String key = block.name();
             int left = block.has("left") ? block.getInt("left") : 0;
             int right = block.has("right") ? block.getInt("right") : 0;
             int top = block.has("top") ? block.getInt("top") : 0;
@@ -133,10 +131,9 @@ public class GameItems {
 
             blocksIds.put(key, blocks.size);
             blocks.put(key, newBlock);
-            block = block.next();
         }
-        while (item != null) {
-            String key = item.name;
+        for (JsonValue item = json.get("items").child(); item != null; item = item.next()) {
+            String key = item.name();
             String name = item.has("name") ? item.getString("name") : key;
             String type = item.has("type") ? item.getString("type") : "item";
             String texture = item.has("texture") ? item.getString("texture") : key;
@@ -144,7 +141,6 @@ public class GameItems {
                     new Sprite(new Texture(Gdx.files.internal("textures/items/" + texture + ".png")));
             itemsIds.put(key, items.size);
             items.put(key, new Item(name, type, sprite));
-            item = item.next();
         }
     }
 
index 4de979050583c688ef682ed3205ac2655bfcb3e0..fdfef6356f3634a73a63675e05aca3e032db02f7 100644 (file)
@@ -2,8 +2,10 @@ 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;
@@ -11,8 +13,8 @@ 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.ControlMode;
 import ru.deadsoftware.cavedroid.misc.Assets;
+import ru.deadsoftware.cavedroid.misc.ControlMode;
 import ru.deadsoftware.cavedroid.misc.states.GameState;
 
 import java.io.Serializable;
@@ -41,8 +43,11 @@ public class GameProc implements Serializable, Disposable {
     public ArrayList<Mob> mobs;
     ArrayList<Drop> drops;
 
-    public boolean isTouchDown, isKeyDown;
-    public int touchDownX, touchDownY, touchDownBtn, keyDownCode;
+    public boolean isKeyDown;
+    public int keyDownCode;
+    boolean isTouchDown;
+    float touchDownX, touchDownY;
+    int touchDownBtn;
     long touchDownTime;
 
     int curX, curY;
@@ -211,21 +216,22 @@ public class GameProc implements Serializable, Disposable {
         }
     }
 
+    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() {
-        switch (touchDownBtn) {
-            case Input.Buttons.RIGHT:
-                useItem(curX, curY, player.inventory[player.slot], true);
+        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;
-                break;
-            case Input.Buttons.LEFT:
-                break;
-            default:
-                if (touchDownY < Assets.invBar.getRegionHeight() &&
-                        touchDownX > renderer.getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 &&
-                        touchDownX < renderer.getWidth() / 2 + (float) Assets.invBar.getRegionWidth() / 2) {
-                    CaveGame.GAME_STATE= GameState.CREATIVE_INV;
-                    isTouchDown = false;
-                }
+            }
         }
     }
 
index c128d85da1c91a1f6dd545fe7c61b1d468cbf408..389994636043d1b7985bb13a411977d82a8d1b00 100644 (file)
@@ -3,16 +3,19 @@ package ru.deadsoftware.cavedroid.game;
 import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.graphics.Color;
 import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
 import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
+import com.badlogic.gdx.math.Rectangle;
 import ru.deadsoftware.cavedroid.CaveGame;
 import ru.deadsoftware.cavedroid.GameScreen;
 import ru.deadsoftware.cavedroid.game.mobs.Mob;
 import ru.deadsoftware.cavedroid.game.objects.Drop;
-import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.ControlMode;
 import ru.deadsoftware.cavedroid.misc.Renderer;
 
 import static ru.deadsoftware.cavedroid.GameScreen.GP;
+import static ru.deadsoftware.cavedroid.misc.Assets.guiMap;
+import static ru.deadsoftware.cavedroid.misc.Assets.textureRegions;
 
 public class GameRenderer extends Renderer {
 
@@ -31,11 +34,9 @@ public class GameRenderer extends Renderer {
 
     private void drawWreck(int bl) {
         if (GP.blockDmg > 0) {
-            spriter.draw(Assets.wreck[
-                            10 * GP.blockDmg /
-                                    GameItems.getBlock(bl).getHp()],
-                    GP.curX * 16 - getCamX(),
-                    GP.curY * 16 - getCamY());
+            int index = 10 * GP.blockDmg / GameItems.getBlock(bl).getHp();
+            String key = "break_" + index;
+            spriter.draw(textureRegions.get(key), GP.curX * 16 - getCamX(), GP.curY * 16 - getCamY());
         }
     }
 
@@ -105,10 +106,11 @@ public class GameRenderer extends Renderer {
 
     @SuppressWarnings("IntegerDivisionInFloatingPointContext")
     private void drawCreative() {
-        float x = getWidth() / 2 - (float) Assets.creativeInv.getRegionWidth() / 2;
-        float y = getHeight() / 2 - (float) Assets.creativeInv.getRegionHeight() / 2;
-        spriter.draw(Assets.creativeInv, x, y);
-        spriter.draw(Assets.creativeScr, x + 156,
+        TextureRegion creative = textureRegions.get("creative");
+        float x = getWidth() / 2 - (float) creative.getRegionWidth() / 2;
+        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++) {
             if (i > 0 && i < GameItems.getItemsSize())
@@ -126,52 +128,54 @@ public class GameRenderer extends Renderer {
             if (GP.player.inventory[i] > 0)
                 if (GameItems.getItem(GP.player.inventory[i]).isBlock()) {
                     spriter.draw(GameItems.getBlock(GameItems.getBlockIdByItemId(GP.player.inventory[i])).getTex(),
-                            x + 8 + i * 18, y + Assets.creativeInv.getRegionHeight() - 24);
+                            x + 8 + i * 18, y + creative.getRegionHeight() - 24);
                 } else {
                     spriter.draw(GameItems.getItem(GP.player.inventory[i]).getTex(),
-                            x + 8 + i * 18, y + Assets.creativeInv.getRegionHeight() - 24);
+                            x + 8 + i * 18, y + creative.getRegionHeight() - 24);
                 }
         }
 
     }
 
     private void drawGUI() {
+        TextureRegion cursor = textureRegions.get("cursor");
+        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) ||
                 GP.controlMode == ControlMode.CURSOR ||
                 !CaveGame.TOUCH)
-            spriter.draw(Assets.guiCur,
+            spriter.draw(cursor,
                     GP.curX * 16 - getCamX(),
                     GP.curY * 16 - getCamY());
-        spriter.draw(Assets.invBar, getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2, 0);
+        spriter.draw(hotbar, getWidth() / 2 - (float) hotbar.getRegionWidth() / 2, 0);
         for (int i = 0; i < 9; i++) {
             if (GP.player.inventory[i] > 0) {
                 if (GameItems.getItem(GP.player.inventory[i]).isBlock()) {
                     spriter.draw(GameItems.getBlock(GameItems.getBlockIdByItemId(GP.player.inventory[i])).getTex(),
-                            getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 + 3 + i * 20,
+                            getWidth() / 2 - (float) hotbar.getRegionWidth() / 2 + 3 + i * 20,
                             3);
                 } else {
                     spriter.draw(GameItems.getItem(GP.player.inventory[i]).getTex(),
-                            getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 + 3 + i * 20,
+                            getWidth() / 2 - (float) hotbar.getRegionWidth() / 2 + 3 + i * 20,
                             3);
                 }
             }
         }
-        spriter.draw(Assets.invBarCur,
-                getWidth() / 2 - (float) Assets.invBar.getRegionWidth() / 2 - 1 + 20 * GP.player.slot,
+        spriter.draw(hotbarSelector,
+                getWidth() / 2 - (float) hotbar.getRegionWidth() / 2 - 1 + 20 * GP.player.slot,
                 -1);
     }
 
     private void drawTouchGui() {
-        spriter.draw(Assets.touchArrows[0], 26, getHeight() - 52);
-        spriter.draw(Assets.touchArrows[1], 0, getHeight() - 26);
-        spriter.draw(Assets.touchArrows[2], 26, getHeight() - 26);
-        spriter.draw(Assets.touchArrows[3], 52, getHeight() - 26);
-        spriter.draw(Assets.touchLMB, getWidth() - 52, getHeight() - 26);
-        spriter.draw(Assets.touchRMB, getWidth() - 26, getHeight() - 26);
-        spriter.draw(Assets.touchMode, 78, getHeight() - 26);
+        for (int i = 0; i < guiMap.size; i++) {
+            Rectangle touchKey = guiMap.getValueAt(i);
+            spriter.draw(textureRegions.get(guiMap.getKeyAt(i)),
+                    touchKey.x, touchKey.y, touchKey.width, touchKey.height);
+        }
         if (GP.controlMode == ControlMode.CURSOR) {
-            spriter.draw(Assets.shade, 83, getHeight() - 21);
+            spriter.draw(textureRegions.get("shade"), 83, getHeight() - 21);
         }
     }
 
@@ -231,9 +235,9 @@ public class GameRenderer extends Renderer {
             shaper.end();
             //=================
         }
-        spriter.begin();
 
         if (GameScreen.SHOW_DEBUG) {
+            spriter.begin();
             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);
@@ -244,8 +248,8 @@ public class GameRenderer extends Renderer {
             drawString("Block: " + GameItems.getBlockKey(GP.world.getForeMap(GP.curX, GP.curY)), 0, 70);
             drawString("Hand: " + GameItems.getItemKey(GP.player.inventory[GP.player.slot]), 0, 80);
             drawString("Game mode: " + GP.player.gameMode, 0, 90);
+            spriter.end();
         }
-        spriter.end();
 
 
     }
index 0f12f18f5548f7de52903d7c58893df76ecb92fe..1c12f03cc2f23654df8920ef61edfdefb3871bba 100644 (file)
@@ -3,8 +3,6 @@ package ru.deadsoftware.cavedroid.game.objects;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.Rectangle;
 import com.badlogic.gdx.math.Vector2;
-import ru.deadsoftware.cavedroid.game.GameItems;
-import ru.deadsoftware.cavedroid.game.GameWorld;
 import ru.deadsoftware.cavedroid.game.mobs.Mob;
 import ru.deadsoftware.cavedroid.misc.Assets;
 
@@ -58,36 +56,36 @@ public class Player extends Mob implements Serializable {
 
     @Override
     public void draw(SpriteBatch spriteBatch, float x, float y) {
-        if (mov.x != 0 || Assets.plSprite[0][2].getRotation() != 0) {
-            Assets.plSprite[0][2].rotate(animDelta);
-            Assets.plSprite[1][2].rotate(-animDelta);
-            Assets.plSprite[0][3].rotate(-animDelta);
-            Assets.plSprite[1][3].rotate(animDelta);
+        if (mov.x != 0 || Assets.playerSprite[0][2].getRotation() != 0) {
+            Assets.playerSprite[0][2].rotate(animDelta);
+            Assets.playerSprite[1][2].rotate(-animDelta);
+            Assets.playerSprite[0][3].rotate(-animDelta);
+            Assets.playerSprite[1][3].rotate(animDelta);
         } else {
-            Assets.plSprite[0][2].setRotation(0);
-            Assets.plSprite[1][2].setRotation(0);
-            Assets.plSprite[0][3].setRotation(0);
-            Assets.plSprite[1][3].setRotation(0);
+            Assets.playerSprite[0][2].setRotation(0);
+            Assets.playerSprite[1][2].setRotation(0);
+            Assets.playerSprite[0][3].setRotation(0);
+            Assets.playerSprite[1][3].setRotation(0);
         }
-        if (Assets.plSprite[0][2].getRotation() >= 60 || Assets.plSprite[0][2].getRotation() <= -60)
+        if (Assets.playerSprite[0][2].getRotation() >= 60 || Assets.playerSprite[0][2].getRotation() <= -60)
             animDelta = -animDelta;
 
         //back hand
-        Assets.plSprite[1][2].setPosition(x - 6, y);
-        Assets.plSprite[1][2].draw(spriteBatch);
+        Assets.playerSprite[1][2].setPosition(x - 6, y);
+        Assets.playerSprite[1][2].draw(spriteBatch);
         //back leg
-        Assets.plSprite[1][3].setPosition(x - 6, y + 10);
-        Assets.plSprite[1][3].draw(spriteBatch);
+        Assets.playerSprite[1][3].setPosition(x - 6, y + 10);
+        Assets.playerSprite[1][3].draw(spriteBatch);
         //front leg
-        Assets.plSprite[0][3].setPosition(x - 6, y + 10);
-        Assets.plSprite[0][3].draw(spriteBatch);
+        Assets.playerSprite[0][3].setPosition(x - 6, y + 10);
+        Assets.playerSprite[0][3].draw(spriteBatch);
         //head
-        spriteBatch.draw(Assets.plSprite[getDirection()][0], x - 2, y - 2);
+        spriteBatch.draw(Assets.playerSprite[getDirection()][0], x - 2, y - 2);
         //body
-        spriteBatch.draw(Assets.plSprite[getDirection()][1], x - 2, y + 8);
+        spriteBatch.draw(Assets.playerSprite[getDirection()][1], x - 2, y + 8);
         //front hand
-        Assets.plSprite[0][2].setPosition(x - 6, y);
-        Assets.plSprite[0][2].draw(spriteBatch);
+        Assets.playerSprite[0][2].setPosition(x - 6, y);
+        Assets.playerSprite[0][2].draw(spriteBatch);
     }
 
     @Override
index ee626202a851f48839c3e7250883a9b1e17f9716..2ae84db12d93926e5c2a19207937b9928609fad0 100644 (file)
@@ -1,23 +1,21 @@
 package ru.deadsoftware.cavedroid.menu;
 
 import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
 import com.badlogic.gdx.utils.Array;
 import org.jetbrains.annotations.NotNull;
 import ru.deadsoftware.cavedroid.CaveGame;
 import ru.deadsoftware.cavedroid.GameScreen;
-import ru.deadsoftware.cavedroid.game.GameItems;
 import ru.deadsoftware.cavedroid.game.GameProc;
 import ru.deadsoftware.cavedroid.game.GameSaver;
 import ru.deadsoftware.cavedroid.menu.objects.Button;
-import ru.deadsoftware.cavedroid.misc.InputHandlerGame;
-import ru.deadsoftware.cavedroid.misc.states.AppState;
-import ru.deadsoftware.cavedroid.misc.Assets;
 import ru.deadsoftware.cavedroid.misc.Renderer;
+import ru.deadsoftware.cavedroid.misc.states.AppState;
 import ru.deadsoftware.cavedroid.misc.states.GameState;
 import ru.deadsoftware.cavedroid.misc.states.MenuState;
 
 import static ru.deadsoftware.cavedroid.GameScreen.GP;
-import static ru.deadsoftware.cavedroid.GameScreen.RENDERER;
+import static ru.deadsoftware.cavedroid.misc.Assets.*;
 
 public class MenuRenderer extends Renderer {
 
@@ -25,14 +23,14 @@ public class MenuRenderer extends Renderer {
     public Array<Button> menuNGBtns;
 
     public MenuRenderer(int width) {
-        super(width, width * ((float) GameScreen.getHeight() / GameScreen.getWidth()));
+        super(width, width * GameScreen.getHeight() / GameScreen.getWidth());
         //main menu
-        menuMainBtns = new Array<Button>();
+        menuMainBtns = new Array<>();
         menuMainBtns.add(new Button("New game", getWidth() / 2 - 100, getHeight() / 4));
         menuMainBtns.add(new Button("Load game", getWidth() / 2 - 100, getHeight() / 4 + 30, GameSaver.exists() ? 1 : 0));
         menuMainBtns.add(new Button("Quit", getWidth() / 2 - 100, getHeight() / 4 + 60));
         //new game menu
-        menuNGBtns = new Array<Button>();
+        menuNGBtns = new Array<>();
         menuNGBtns.add(new Button("Survival", getWidth() / 2 - 100, getHeight() / 4, 0));
         menuNGBtns.add(new Button("Creative", getWidth() / 2 - 100, getHeight() / 4 + 30));
         menuNGBtns.add(new Button("Back", getWidth() / 2 - 100, getHeight() / 4 + 60));
@@ -43,10 +41,7 @@ public class MenuRenderer extends Renderer {
         GP = new GameProc(gameMode);
         GP.player.respawn();
         GameSaver.save(GP);
-        RENDERER = GP.renderer;
-        Gdx.input.setInputProcessor(new InputHandlerGame());
-        CaveGame.APP_STATE = AppState.GAME;
-        CaveGame.GAME_STATE = GameState.PLAY;
+        CaveGame.APP_STATE = AppState.LOAD;
     }
 
     public void buttonClicked(@NotNull Button button) {
@@ -56,6 +51,7 @@ public class MenuRenderer extends Renderer {
                 break;
             case "load game":
                 CaveGame.APP_STATE = AppState.LOAD;
+                GP = GameSaver.load();
                 break;
             case "quit":
                 Gdx.app.exit();
@@ -73,11 +69,11 @@ public class MenuRenderer extends Renderer {
     }
 
     private void drawButton(Button button) {
-        spriter.draw(Assets.menuBtn[button.getType()], button.getX(), button.getY());
+        spriter.draw(textureRegions.get("button_" + button.getType()), button.getX(), button.getY());
         setFontColor(255, 255, 255);
         drawString(button.getLabel(),
-                (button.getX() + button.getWidth() / 2) - (float) Assets.getStringWidth(button.getLabel()) / 2,
-                (button.getY() + button.getHeight() / 2) - (float) Assets.getStringHeight(button.getLabel()) / 2);
+                (button.getX() + button.getWidth() / 2) - (float) getStringWidth(button.getLabel()) / 2,
+                (button.getY() + button.getHeight() / 2) - (float) getStringHeight(button.getLabel()) / 2);
     }
 
     private void drawButtons(Array<Button> buttons) {
@@ -99,14 +95,17 @@ public class MenuRenderer extends Renderer {
 
     @Override
     public void render() {
+        TextureRegion shade = textureRegions.get("shade");
+        TextureRegion gamelogo = textureRegions.get("gamelogo");
+
         spriter.begin();
         for (int x = 0; x <= getWidth() / 16; x++) {
             for (int y = 0; y <= getHeight() / 16; y++) {
-                spriter.draw(GameItems.getBlock(3).getTex(), x * 16, y * 16);
-                spriter.draw(Assets.shade, x * 16, y * 16);
+//                spriter.draw(GameItems.getBlock(3).getTex(), x * 16, y * 16);
+                spriter.draw(shade, x * 16, y * 16);
             }
         }
-        spriter.draw(Assets.gameLogo, getWidth() / 2 - (float) Assets.gameLogo.getWidth() / 2, 8);
+        spriter.draw(gamelogo, getWidth() / 2 - (float) gamelogo.getRegionWidth() / 2, 8);
 
         switch (CaveGame.MENU_STATE) {
             case MAIN:
@@ -128,7 +127,7 @@ public class MenuRenderer extends Renderer {
         }
 
         drawString("CaveDroid " + CaveGame.VERSION, 0,
-                getHeight() - Assets.getStringHeight("CaveDroid " + CaveGame.VERSION) * 1.5f);
+                getHeight() - getStringHeight("CaveDroid " + CaveGame.VERSION) * 1.5f);
         spriter.end();
     }
 }
index 0b0b109face3f64befb701007e032eec19d94a90..30c346b32e7d9fe835e557370cb9e9fa5b51b9c5 100644 (file)
@@ -6,77 +6,59 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont;
 import com.badlogic.gdx.graphics.g2d.GlyphLayout;
 import com.badlogic.gdx.graphics.g2d.Sprite;
 import com.badlogic.gdx.graphics.g2d.TextureRegion;
-import ru.deadsoftware.cavedroid.CaveGame;
+import com.badlogic.gdx.math.Rectangle;
+import com.badlogic.gdx.utils.ArrayMap;
+import com.badlogic.gdx.utils.JsonReader;
+import com.badlogic.gdx.utils.JsonValue;
 
-public class Assets {
-
-    private static GlyphLayout layout;
-
-    public static BitmapFont mcFont;
-
-    public static Sprite gameLogo;
+import java.util.HashMap;
 
-    public static Texture menuBtnTex;
-    public static TextureRegion[] menuBtn = new TextureRegion[3];
-
-    public static Texture plTex;
-    public static Sprite[][] plSprite = new Sprite[2][4];
+public class Assets {
 
-    public static Texture pigTex;
+    public static JsonReader jsonReader = new JsonReader();
+    public static Sprite[][] playerSprite = new Sprite[2][4];
+    public static HashMap<String, TextureRegion> textureRegions = new HashMap<>();
+    public static ArrayMap<String, Rectangle> guiMap = new ArrayMap<>();
     public static Sprite[][] pigSprite = new Sprite[2][2];
+    static BitmapFont minecraftFont;
+    private static GlyphLayout glyphLayout = new GlyphLayout();
 
-    public static Texture shade;
-
-    public static Texture gui;
-    public static TextureRegion invBar;
-    public static TextureRegion invBarCur;
-    public static TextureRegion guiCur;
-
-    public static Texture wreckTex;
-    public static TextureRegion[] wreck = new TextureRegion[10];
-
-    public static Texture creativeTex;
-    public static TextureRegion creativeInv;
-    public static TextureRegion creativeScr;
-
-    public static Texture touchGui;
-    public static TextureRegion[] touchArrows = new TextureRegion[4];
-    public static TextureRegion touchLMB, touchRMB;
-    public static TextureRegion touchMode;
-    public static TextureRegion touchSpace;
+    private static TextureRegion flippedRegion(Texture texture, int x, int y, int width, int height) {
+        return new TextureRegion(texture, x, y + height, width, -height);
+    }
 
     private static void loadPlayer() {
-        plTex = new Texture(Gdx.files.internal("mobs/char.png"));
+        Texture plTex = new Texture(Gdx.files.internal("mobs/char.png"));
         //LOOK TO LEFT
         //head
-        plSprite[0][0] = new Sprite(new TextureRegion(plTex, 0, 0, 12, 12));
-        plSprite[0][0].flip(false, true);
+        playerSprite[0][0] = new Sprite(new TextureRegion(plTex, 0, 0, 12, 12));
+        playerSprite[0][0].flip(false, true);
         //body
-        plSprite[0][1] = new Sprite(new TextureRegion(plTex, 0, 13, 12, 12));
-        plSprite[0][1].flip(false, true);
+        playerSprite[0][1] = new Sprite(new TextureRegion(plTex, 0, 13, 12, 12));
+        playerSprite[0][1].flip(false, true);
         //hand
-        plSprite[0][2] = new Sprite(new TextureRegion(plTex, 25, 5, 20, 20));
-        plSprite[0][2].flip(false, true);
+        playerSprite[0][2] = new Sprite(new TextureRegion(plTex, 25, 5, 20, 20));
+        playerSprite[0][2].flip(false, true);
         //leg
-        plSprite[0][3] = new Sprite(new TextureRegion(plTex, 25, 27, 20, 20));
-        plSprite[0][3].flip(false, true);
+        playerSprite[0][3] = new Sprite(new TextureRegion(plTex, 25, 27, 20, 20));
+        playerSprite[0][3].flip(false, true);
         //LOOK TO RIGHT
         //head
-        plSprite[1][0] = new Sprite(new TextureRegion(plTex, 13, 0, 12, 12));
-        plSprite[1][0].flip(false, true);
+        playerSprite[1][0] = new Sprite(new TextureRegion(plTex, 13, 0, 12, 12));
+        playerSprite[1][0].flip(false, true);
         //body
-        plSprite[1][1] = new Sprite(new TextureRegion(plTex, 13, 13, 12, 12));
-        plSprite[1][1].flip(false, true);
+        playerSprite[1][1] = new Sprite(new TextureRegion(plTex, 13, 13, 12, 12));
+        playerSprite[1][1].flip(false, true);
         //hand
-        plSprite[1][2] = new Sprite(new TextureRegion(plTex, 37, 5, 20, 20));
-        plSprite[1][2].flip(false, true);
+        playerSprite[1][2] = new Sprite(new TextureRegion(plTex, 37, 5, 20, 20));
+        playerSprite[1][2].flip(false, true);
         //leg
-        plSprite[1][3] = new Sprite(new TextureRegion(plTex, 37, 27, 20, 20));
-        plSprite[1][3].flip(false, true);
+        playerSprite[1][3] = new Sprite(new TextureRegion(plTex, 37, 27, 20, 20));
+        playerSprite[1][3].flip(false, true);
     }
 
     private static void loadPig() {
-        pigTex = new Texture(Gdx.files.internal("mobs/pig.png"));
+        Texture pigTex = new Texture(Gdx.files.internal("mobs/pig.png"));
         pigSprite[0][0] = new Sprite(new TextureRegion(pigTex, 0, 0, 25, 12));
         pigSprite[0][0].flip(false, true);
         pigSprite[1][0] = new Sprite(new TextureRegion(pigTex, 0, 12, 25, 12));
@@ -87,68 +69,48 @@ public class Assets {
         pigSprite[1][1].flip(false, true);
     }
 
-    public static void load() {
-        mcFont = new BitmapFont(Gdx.files.internal("font.fnt"), true);
-        mcFont.getData().setScale(.375f);
-
-        layout = new GlyphLayout();
-
-        gameLogo = new Sprite(new Texture(Gdx.files.internal("gamelogo.png")));
-        gameLogo.flip(false, true);
-
-        menuBtnTex = new Texture(Gdx.files.internal("buttons.png"));
-        for (int i = 0; i < 3; i++) {
-            menuBtn[i] = new TextureRegion(menuBtnTex, 0, 20 * i, 200, 20);
-            menuBtn[i].flip(false, true);
+    /**
+     * Loads texture names and sizes from <b>json/texture_regions.json</b>, cuts them to TextureRegions
+     * and puts to {@link #textureRegions} HashMap
+     */
+    private static void loadJSON() {
+        JsonValue json = Assets.jsonReader.parse(Gdx.files.internal("json/texture_regions.json"));
+        for (JsonValue file = json.child(); file != null; file = file.next()) {
+            Texture texture = new Texture(Gdx.files.internal(file.name() + ".png"));
+            for (JsonValue key = file.child(); key != null; key = key.next()) {
+                int x = key.has("x") ? key.getInt("x") : 0;
+                int y = key.has("y") ? key.getInt("y") : 0;
+                int w = key.has("w") ? key.getInt("w") : texture.getWidth();
+                int h = key.has("h") ? key.getInt("h") : texture.getHeight();
+                textureRegions.put(key.name(), flippedRegion(texture, x, y, w, h));
+            }
         }
+    }
 
+    public static void load() {
+        minecraftFont = new BitmapFont(Gdx.files.internal("font.fnt"), true);
+        minecraftFont.getData().setScale(.375f);
         loadPlayer();
         loadPig();
-
-        shade = new Texture(Gdx.files.internal("shade.png"));
-
-        gui = new Texture(Gdx.files.internal("gui.png"));
-        guiCur = new TextureRegion(gui, 0, 0, 16, 16);
-        invBar = new TextureRegion(gui, 0, 16, 182, 22);
-        invBarCur = new TextureRegion(gui, 0, 38, 24, 24);
-
-        creativeTex = new Texture(Gdx.files.internal("allitems.png"));
-        creativeInv = new TextureRegion(creativeTex, 0, 0, 176, 136);
-        creativeInv.flip(false, true);
-        creativeScr = new TextureRegion(creativeTex, 3, 137, 12, 15);
-        creativeScr.flip(false, true);
-
-        wreckTex = new Texture(Gdx.files.internal("break.png"));
-        for (int i = 0; i < 10; i++) {
-            wreck[i] = new TextureRegion(wreckTex, 16 * i, 0, 16, 16);
-        }
-
-        if (CaveGame.TOUCH) {
-            touchGui = new Texture(Gdx.files.internal("touch_gui.png"));
-            for (int i = 0; i < 4; i++) {
-                touchArrows[i] = new TextureRegion(touchGui, i * 26, 0, 26, 26);
-                touchArrows[i].flip(false, true);
-            }
-            touchLMB = new TextureRegion(touchGui, 0, 26, 26, 26);
-            touchLMB.flip(false, true);
-            touchRMB = new TextureRegion(touchGui, 52, 26, 26, 26);
-            touchRMB.flip(false, true);
-            touchMode = new TextureRegion(touchGui, 26, 26, 26, 26);
-            touchMode.flip(false, true);
-            touchSpace = new TextureRegion(touchGui, 0, 52, 104, 26);
-            touchSpace.flip(false, true);
-        }
-
+        loadJSON();
     }
 
+    /**
+     * @param s string whose width you want to know
+     * @return A width of string written in {@link #minecraftFont} in pixels
+     */
     public static int getStringWidth(String s) {
-        layout.setText(mcFont, s);
-        return (int) layout.width;
+        glyphLayout.setText(minecraftFont, s);
+        return (int) glyphLayout.width;
     }
 
+    /**
+     * @param s string whose height you want to know
+     * @return A height of string written in {@link #minecraftFont} in pixels
+     */
     public static int getStringHeight(String s) {
-        layout.setText(mcFont, s);
-        return (int) layout.height;
+        glyphLayout.setText(minecraftFont, s);
+        return (int) glyphLayout.height;
     }
 
 }
index c00521f1311570106c91e8aecc5d2b4a1458238e..9ba00bcfca9ee5e393cb188651ed18b355bd23d7 100644 (file)
@@ -1,18 +1,63 @@
 package ru.deadsoftware.cavedroid.misc;
 
+import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.Input;
-import com.badlogic.gdx.InputProcessor;
+import com.badlogic.gdx.InputAdapter;
+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.*;
+import static ru.deadsoftware.cavedroid.GameScreen.GP;
 
-public class InputHandlerGame implements InputProcessor {
+public class InputHandlerGame extends InputAdapter {
+
+    private static final int
+            UP = 0,
+            DOWN = 1,
+            LEFT = 2,
+            RIGHT = 3,
+            ALT = 4,
+            LMB = 5,
+            RMB = 6;
 
     private GameInput gameInput;
 
     public InputHandlerGame() {
         this.gameInput = new GameInput();
+        loadTouchButtonsFromJSON();
+    }
+
+    private void loadTouchButtonsFromJSON() {
+        JsonValue json = Assets.jsonReader.parse(Gdx.files.internal("json/touch_buttons.json"));
+        for (JsonValue key = json.child(); key != null; key = key.next()) {
+            float x = key.getFloat("x");
+            float y = key.getFloat("y");
+            float w = key.getFloat("w");
+            float h = key.getFloat("h");
+            if (x < 0) x = GP.renderer.getWidth() + x;
+            if (y < 0) y = GP.renderer.getHeight() + y;
+            Assets.guiMap.put(key.name(), new Rectangle(x, y, w, h));
+        }
+
+    }
+
+    private float transformScreenX(int screenX) {
+        return GP.renderer.getWidth() / GameScreen.getWidth() * screenX;
+    }
+
+    private float transformScreenY(int screenY) {
+        return GP.renderer.getHeight() / GameScreen.getHeight() * screenY;
+    }
+
+    private int getTouchedKey(float touchX, float touchY) {
+        for (int i = 0; i < Assets.guiMap.size; i++) {
+            if (Assets.guiMap.getValueAt(i).contains(touchX, touchY)) {
+                return i;
+            }
+        }
+        return -1;
     }
 
     @Override
@@ -27,96 +72,88 @@ public class InputHandlerGame implements InputProcessor {
         return false;
     }
 
-    @Override
-    public boolean keyTyped(char character) {
-        return false;
-    }
-
     @Override
     public boolean touchDown(int screenX, int screenY, int pointer, int button) {
-        screenX *= GP.renderer.getWidth() / getWidth();
-        screenY *= GP.renderer.getHeight() / getHeight();
+        float touchX = transformScreenX(screenX);
+        float touchY = transformScreenY(screenY);
 
         if (CaveGame.TOUCH) {
-            if (screenX > 26 && screenX < 52 && screenY > GP.renderer.getHeight() - 52 &&
-                    screenY < GP.renderer.getHeight() - 26) {
-                if (GP.controlMode == ControlMode.CURSOR) {
-                    gameInput.keyDown(Input.Keys.W);
-                } else {
-                    gameInput.keyDown(Input.Keys.SPACE);
-                }
-            } else if (screenX > 0 && screenX < 26 && screenY > GP.renderer.getHeight() - 26) {
-                gameInput.keyDown(Input.Keys.A);
-            } else if (screenX > 26 && screenX < 52 && screenY > GP.renderer.getHeight() - 26) {
-                if (GP.controlMode == ControlMode.CURSOR) gameInput.keyDown(Input.Keys.S);
-                else gameInput.keyDown(Input.Keys.CONTROL_LEFT);
-            } else if (screenX > 52 && screenX < 78 && screenY > GP.renderer.getHeight() - 26) {
-                gameInput.keyDown(Input.Keys.D);
-            } else if (screenX > 78 && screenX < 104 && screenY > GP.renderer.getHeight() - 26) {
-                gameInput.keyDown(Input.Keys.ALT_LEFT);
-            } else if (screenX > GP.renderer.getWidth() - 52 && screenX < GP.renderer.getWidth() - 26 &&
-                    screenY > GP.renderer.getHeight() - 26) {
-                gameInput.touchDown(screenX, screenY, Input.Buttons.LEFT);
-            } else if (screenX > GP.renderer.getWidth() - 26 && screenY > screenY - 26) {
-                gameInput.touchDown(screenX, screenY, Input.Buttons.RIGHT);
-            } else {
-                gameInput.touchDown(screenX, screenY, -1);
+            int touchedKey = getTouchedKey(touchX, touchY);
+            switch (touchedKey) {
+                case UP:
+                    gameInput.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);
+                    break;
+                case LEFT:
+                    gameInput.keyDown(Input.Keys.A);
+                    break;
+                case RIGHT:
+                    gameInput.keyDown(Input.Keys.D);
+                    break;
+                case ALT:
+                    gameInput.keyDown(Input.Keys.ALT_LEFT);
+                    break;
+                case LMB:
+                    gameInput.touchDown(touchX, touchY, Input.Buttons.LEFT);
+                    break;
+                case RMB:
+                    gameInput.touchDown(touchX, touchY, Input.Buttons.RIGHT);
+                    break;
+                default:
+                    gameInput.touchDown(touchX, touchY, touchedKey);
             }
         } else {
-            gameInput.touchDown(screenX, screenY, button);
+            gameInput.touchDown(touchX, touchY, button);
         }
         return false;
     }
 
     @Override
     public boolean touchUp(int screenX, int screenY, int pointer, int button) {
-        screenX *= GP.renderer.getWidth() / getWidth();
-        screenY *= GP.renderer.getHeight() / getHeight();
+        float touchX = transformScreenX(screenX);
+        float touchY = transformScreenY(screenY);
+
         if (CaveGame.TOUCH) {
-            if (screenX > 26 && screenX < 52 && screenY > GP.renderer.getHeight() - 52 &&
-                    screenY < GP.renderer.getHeight() - 26) {
-                if (GP.controlMode == ControlMode.CURSOR) gameInput.keyUp(Input.Keys.W);
-                else gameInput.keyUp(Input.Keys.SPACE);
-            } else if (screenX > 0 && screenX < 26 && screenY > GP.renderer.getHeight() - 26) {
-                gameInput.keyUp(Input.Keys.A);
-            } else if (screenX > 26 && screenX < 52 && screenY > GP.renderer.getHeight() - 26) {
-                if (GP.controlMode == ControlMode.CURSOR) gameInput.keyUp(Input.Keys.S);
-                else gameInput.keyUp(Input.Keys.CONTROL_LEFT);
-            } else if (screenX > 52 && screenX < 78 && screenY > GP.renderer.getHeight() - 26) {
-                gameInput.keyUp(Input.Keys.D);
-            } else if (screenX > 78 && screenX < 104 && screenY > GP.renderer.getHeight() - 26) {
-                gameInput.keyUp(Input.Keys.ALT_LEFT);
-            } else if (screenX > GP.renderer.getWidth() - 52 && screenX < GP.renderer.getWidth() - 26 &&
-                    screenY > GP.renderer.getHeight() - 26) {
-                gameInput.touchUp(screenX, screenY, Input.Buttons.LEFT);
-            } else if (screenX > GP.renderer.getWidth() - 26 && screenY > screenY - 26) {
-                gameInput.touchUp(screenX, screenY, Input.Buttons.RIGHT);
-            } else {
-                gameInput.touchUp(screenX, screenY, -1);
+            int touchedKey = getTouchedKey(touchX, touchY);
+            switch (touchedKey) {
+                case UP:
+                case DOWN:
+                case LEFT:
+                case RIGHT:
+                case ALT:
+                    gameInput.keyUp(GP.keyDownCode);
+                    break;
+                case LMB:
+                    gameInput.touchUp(touchX, touchY, Input.Buttons.LEFT);
+                    break;
+                case RMB:
+                    gameInput.touchUp(touchX, touchY, Input.Buttons.RIGHT);
+                    break;
+                default:
+                    gameInput.touchUp(touchX, touchY, touchedKey);
             }
         } else {
-            gameInput.touchUp(screenX, screenY, button);
+            gameInput.touchUp(touchX, touchY, button);
         }
         return false;
     }
 
     @Override
     public boolean touchDragged(int screenX, int screenY, int pointer) {
-        screenX *= GP.renderer.getWidth() / getWidth();
-        screenY *= GP.renderer.getHeight() / getHeight();
-        if (GP.isKeyDown && (screenX > 78 || screenY < GP.renderer.getHeight() - 52)) {
-            gameInput.keyUp(GP.keyDownCode);
+        float touchX = transformScreenX(screenX);
+        float touchY = transformScreenY(screenY);
+        if (CaveGame.TOUCH && GP.isKeyDown) {
+            if (getTouchedKey(touchX, touchY) == -1) {
+                gameInput.keyUp(GP.keyDownCode);
+            }
         } else {
-            gameInput.touchDragged(screenX, screenY);
+            gameInput.touchDragged(touchX, touchY);
         }
         return false;
     }
 
-    @Override
-    public boolean mouseMoved(int screenX, int screenY) {
-        return false;
-    }
-
     @Override
     public boolean scrolled(int amount) {
         gameInput.scrolled(amount);
index 637eed7c3b3f6dfd3f73fb35b94bbb122f7cec10..18e077ac586e31ff158f21b7d6da1e41d7b5022f 100644 (file)
@@ -2,7 +2,6 @@ package ru.deadsoftware.cavedroid.misc;
 
 import com.badlogic.gdx.graphics.OrthographicCamera;
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.badlogic.gdx.graphics.g2d.SpriteCache;
 import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
 import ru.deadsoftware.cavedroid.GameScreen;
 
@@ -12,7 +11,6 @@ public abstract class Renderer {
 
     protected ShapeRenderer shaper;
     protected SpriteBatch spriter;
-    protected SpriteCache spriteCache;
 
     public Renderer() {
         this(GameScreen.getWidth(), GameScreen.getHeight());
@@ -25,8 +23,6 @@ public abstract class Renderer {
         shaper.setProjectionMatrix(camera.combined);
         spriter = new SpriteBatch();
         spriter.setProjectionMatrix(camera.combined);
-        spriteCache = new SpriteCache();
-        spriteCache.setProjectionMatrix(camera.combined);
     }
 
     public float getWidth() {
@@ -50,19 +46,19 @@ public abstract class Renderer {
     }
 
     public void setFontScale(float scale) {
-        Assets.mcFont.getData().setScale(scale);
+        Assets.minecraftFont.getData().setScale(scale);
     }
 
     protected void setFontColor(int r, int g, int b) {
-        Assets.mcFont.setColor(r / 255f, g / 255f, b / 255f, 1f);
+        Assets.minecraftFont.setColor(r / 255f, g / 255f, b / 255f, 1f);
     }
 
     protected void drawString(String str, float x, float y) {
-        Assets.mcFont.draw(spriter, str, x, y);
+        Assets.minecraftFont.draw(spriter, str, x, y);
     }
 
     protected void drawString(String str) {
-        Assets.mcFont.draw(spriter, str,
+        Assets.minecraftFont.draw(spriter, str,
                 getWidth() / 2 - (float) Assets.getStringWidth(str) / 2,
                 getHeight() / 2 - (float) Assets.getStringHeight(str) / 2);
     }