DEADSOFTWARE

Make separate textures for mob limbs #8
authorfred-boy <fredboy@protonmail.com>
Mon, 23 Dec 2019 11:32:49 +0000 (18:32 +0700)
committerfred-boy <fredboy@protonmail.com>
Mon, 23 Dec 2019 11:49:48 +0000 (18:49 +0700)
21 files changed:
android/assets/mobs/char.png [deleted file]
android/assets/mobs/char/0_0.png [new file with mode: 0644]
android/assets/mobs/char/0_1.png [new file with mode: 0644]
android/assets/mobs/char/0_2.png [new file with mode: 0644]
android/assets/mobs/char/0_3.png [new file with mode: 0644]
android/assets/mobs/char/1_0.png [new file with mode: 0644]
android/assets/mobs/char/1_1.png [new file with mode: 0644]
android/assets/mobs/char/1_2.png [new file with mode: 0644]
android/assets/mobs/char/1_3.png [new file with mode: 0644]
android/assets/mobs/pig.png [deleted file]
android/assets/mobs/pig/0_0.png [new file with mode: 0644]
android/assets/mobs/pig/0_1.png [new file with mode: 0644]
android/assets/mobs/pig/1_0.png [new file with mode: 0644]
android/assets/mobs/pig/1_1.png [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/GameItems.java
core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java
core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java
core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java
core/src/ru/deadsoftware/cavedroid/game/mobs/Pig.java
core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
core/src/ru/deadsoftware/cavedroid/misc/Assets.java

diff --git a/android/assets/mobs/char.png b/android/assets/mobs/char.png
deleted file mode 100644 (file)
index 382b6c7..0000000
Binary files a/android/assets/mobs/char.png and /dev/null differ
diff --git a/android/assets/mobs/char/0_0.png b/android/assets/mobs/char/0_0.png
new file mode 100644 (file)
index 0000000..6ff1ff5
Binary files /dev/null and b/android/assets/mobs/char/0_0.png differ
diff --git a/android/assets/mobs/char/0_1.png b/android/assets/mobs/char/0_1.png
new file mode 100644 (file)
index 0000000..5a31625
Binary files /dev/null and b/android/assets/mobs/char/0_1.png differ
diff --git a/android/assets/mobs/char/0_2.png b/android/assets/mobs/char/0_2.png
new file mode 100644 (file)
index 0000000..0eb4f93
Binary files /dev/null and b/android/assets/mobs/char/0_2.png differ
diff --git a/android/assets/mobs/char/0_3.png b/android/assets/mobs/char/0_3.png
new file mode 100644 (file)
index 0000000..660f3cb
Binary files /dev/null and b/android/assets/mobs/char/0_3.png differ
diff --git a/android/assets/mobs/char/1_0.png b/android/assets/mobs/char/1_0.png
new file mode 100644 (file)
index 0000000..2995fa7
Binary files /dev/null and b/android/assets/mobs/char/1_0.png differ
diff --git a/android/assets/mobs/char/1_1.png b/android/assets/mobs/char/1_1.png
new file mode 100644 (file)
index 0000000..6805730
Binary files /dev/null and b/android/assets/mobs/char/1_1.png differ
diff --git a/android/assets/mobs/char/1_2.png b/android/assets/mobs/char/1_2.png
new file mode 100644 (file)
index 0000000..d0701b5
Binary files /dev/null and b/android/assets/mobs/char/1_2.png differ
diff --git a/android/assets/mobs/char/1_3.png b/android/assets/mobs/char/1_3.png
new file mode 100644 (file)
index 0000000..c0ef26c
Binary files /dev/null and b/android/assets/mobs/char/1_3.png differ
diff --git a/android/assets/mobs/pig.png b/android/assets/mobs/pig.png
deleted file mode 100644 (file)
index 826d725..0000000
Binary files a/android/assets/mobs/pig.png and /dev/null differ
diff --git a/android/assets/mobs/pig/0_0.png b/android/assets/mobs/pig/0_0.png
new file mode 100644 (file)
index 0000000..75c3b89
Binary files /dev/null and b/android/assets/mobs/pig/0_0.png differ
diff --git a/android/assets/mobs/pig/0_1.png b/android/assets/mobs/pig/0_1.png
new file mode 100644 (file)
index 0000000..a36c37e
Binary files /dev/null and b/android/assets/mobs/pig/0_1.png differ
diff --git a/android/assets/mobs/pig/1_0.png b/android/assets/mobs/pig/1_0.png
new file mode 100644 (file)
index 0000000..8ef2387
Binary files /dev/null and b/android/assets/mobs/pig/1_0.png differ
diff --git a/android/assets/mobs/pig/1_1.png b/android/assets/mobs/pig/1_1.png
new file mode 100644 (file)
index 0000000..c549d26
Binary files /dev/null and b/android/assets/mobs/pig/1_1.png differ
index 625938fd5fb76c07ce2cd1c56b24deca3cbe640c..8c3720d42927dffb5da03e7c95c677447f031f61 100644 (file)
@@ -19,77 +19,77 @@ public class GameItems {
     private static final ArrayMap<String, Block> blocks = new ArrayMap<>();
     private static final ArrayMap<String, Item> items = new ArrayMap<>();
 
-    static boolean isFluid(int id) {
+    public static boolean isFluid(int id) {
         return getBlock(id).isFluid();
     }
 
-    static boolean isWater(int id) {
+    public static boolean isWater(int id) {
         return getBlock(id).getMeta().equals("water");
     }
 
-    static boolean isLava(int id) {
+    public static boolean isLava(int id) {
         return getBlock(id).getMeta().equals("lava");
     }
 
-    static boolean isSlab(int id) {
+    public static boolean isSlab(int id) {
         return getBlock(id).getMeta().equals("slab");
     }
 
-    static boolean fluidCanFlowThere(int thisId, int thatId) {
+    public 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);
     }
 
-    static Block getBlock(int id) {
+    public static Block getBlock(int id) {
         return blocks.getValueAt(id);
     }
 
-    static Item getItem(int id) {
+    public static Item getItem(int id) {
         return items.getValueAt(id);
     }
 
-    static Block getBlock(String key) {
+    public static Block getBlock(String key) {
         return blocks.getValueAt(blocksIds.get(key));
     }
 
-    static Item getItem(String key) {
+    public static Item getItem(String key) {
         return items.getValueAt(itemsIds.get(key));
     }
 
-    static int getBlockId(String key) {
+    public static int getBlockId(String key) {
         return blocksIds.get(key);
     }
 
-    static int getItemId(String key) {
+    public static int getItemId(String key) {
         return itemsIds.get(key);
     }
 
-    static String getBlockKey(int id) {
+    public static String getBlockKey(int id) {
         return blocks.getKeyAt(id);
     }
 
-    static String getItemKey(int id) {
+    public static String getItemKey(int id) {
         return items.getKeyAt(id);
     }
 
-    static int getBlockIdByItemId(int id) {
+    public static int getBlockIdByItemId(int id) {
         return getBlockId(items.getKeyAt(id));
     }
 
-    static int getBlocksSize() {
+    public static int getBlocksSize() {
         return blocks.size;
     }
 
-    static int getItemsSize() {
+    public static int getItemsSize() {
         return items.size;
     }
 
-    static Sprite getBlockTex(int id) {
+    public static Sprite getBlockTex(int id) {
         return getBlock(id).getTex();
     }
 
-    static Sprite getItemTex(int id) {
+    public static Sprite getItemTex(int id) {
         if (items.getValueAt(id).getType().equals("block")) {
             return getBlockTex(id);
         } else {
index 3eb10ebcda3a8474ded187c409ad933a2027088b..70879e4f1499d2db2d91d19107a9852d45c31ede 100644 (file)
@@ -2,7 +2,7 @@ package ru.deadsoftware.cavedroid.game.mobs;
 
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.Vector2;
-import ru.deadsoftware.cavedroid.misc.Assets;
+import ru.deadsoftware.cavedroid.game.GameItems;
 
 import static ru.deadsoftware.cavedroid.GameScreen.GP;
 
@@ -37,7 +37,7 @@ public class FallingGravel extends Mob {
 
     @Override
     public void draw(SpriteBatch spriteBatch, float x, float y) {
-        spriteBatch.draw(Assets.gravelSprite, x, y);
+        spriteBatch.draw(GameItems.getBlockTex(11), x, y);
     }
 
 }
index 89b20e1add566962fd19a873e0549ed9e3161a69..a52d92008a24370a3d411b07538fd6c529acc8e6 100644 (file)
@@ -2,7 +2,7 @@ package ru.deadsoftware.cavedroid.game.mobs;
 
 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
 import com.badlogic.gdx.math.Vector2;
-import ru.deadsoftware.cavedroid.misc.Assets;
+import ru.deadsoftware.cavedroid.game.GameItems;
 
 import static ru.deadsoftware.cavedroid.GameScreen.GP;
 
@@ -37,7 +37,7 @@ public class FallingSand extends Mob {
 
     @Override
     public void draw(SpriteBatch spriteBatch, float x, float y) {
-        spriteBatch.draw(Assets.sandSprite, x, y);
+        spriteBatch.draw(GameItems.getBlockTex(10), x, y);
     }
 
 }
index 5f73a6b4720af3ad3f185a81d6ec47fb65ac06de..698ebef8c847ba3f5c2a802d0ba1c045cfacd6a4 100644 (file)
@@ -21,6 +21,7 @@ public abstract class Mob extends Rectangle implements Serializable {
     private Direction dir;
     private boolean dead;
     private boolean canJump, flyMode;
+
     /**
      * @param x      in pixels
      * @param y      in pixels
index e37ab3e3d4fe2db20dbff6e2a13052fd5cf96b7d..394d9be23533200e00478f3af5ede019a2c37d51 100644 (file)
@@ -46,16 +46,16 @@ public class Pig extends Mob {
         pigSprite[0][1].setRotation(getAnim());
         pigSprite[1][1].setRotation(-getAnim());
         //back legs
-        pigSprite[1][1].setPosition(x - 4 + (9 - dirMultiplier() * 9), y + 6);
+        pigSprite[1][1].setPosition(x + (9 - dirMultiplier() * 9), y + 12);
         pigSprite[1][1].draw(spriteBatch);
-        pigSprite[1][1].setPosition(x + 17 - (9 * dirMultiplier()), y + 6);
+        pigSprite[1][1].setPosition(x + 21 - (9 * dirMultiplier()), y + 12);
         pigSprite[1][1].draw(spriteBatch);
+        //head & body
+        spriteBatch.draw(Assets.pigSprite[dirMultiplier()][0], x, y);
         //front legs
-        pigSprite[0][1].setPosition(x - 4 + (9 - dirMultiplier() * 9), y + 6);
+        pigSprite[0][1].setPosition(x + (9 - dirMultiplier() * 9), y + 12);
         pigSprite[0][1].draw(spriteBatch);
-        pigSprite[0][1].setPosition(x + 17 - (9 * dirMultiplier()), y + 6);
+        pigSprite[0][1].setPosition(x + 21 - (9 * dirMultiplier()), y + 12);
         pigSprite[0][1].draw(spriteBatch);
-        //head & body
-        spriteBatch.draw(Assets.pigSprite[dirMultiplier()][0], x, y);
     }
 }
index cfa1cd8bb8c0650a4264eebd9be8aff8a534aa24..fd7101c7dbd0dafbefab5675098e47cb014723f7 100644 (file)
@@ -9,8 +9,8 @@ import static ru.deadsoftware.cavedroid.GameScreen.GP;
 public class Player extends Mob {
 
     public final int[] inventory;
-    public final int gameMode;
     public int slot;
+    public final int gameMode;
     public boolean swim;
 
     public Player(int gameMode) {
@@ -74,20 +74,20 @@ public class Player extends Mob {
         }
 
         //back hand
-        Assets.playerSprite[1][2].setPosition(x - 6, y);
+        Assets.playerSprite[1][2].setPosition(x + 2, y + 8);
         Assets.playerSprite[1][2].draw(spriteBatch);
         //back leg
-        Assets.playerSprite[1][3].setPosition(x - 6, y + 10);
+        Assets.playerSprite[1][3].setPosition(x + 2, y + 20);
         Assets.playerSprite[1][3].draw(spriteBatch);
         //front leg
-        Assets.playerSprite[0][3].setPosition(x - 6, y + 10);
+        Assets.playerSprite[0][3].setPosition(x + 2, y + 20);
         Assets.playerSprite[0][3].draw(spriteBatch);
         //head
-        spriteBatch.draw(Assets.playerSprite[dirMultiplier()][0], x - 2, y - 2);
+        spriteBatch.draw(Assets.playerSprite[dirMultiplier()][0], x, y);
         //body
-        spriteBatch.draw(Assets.playerSprite[dirMultiplier()][1], x - 2, y + 8);
+        spriteBatch.draw(Assets.playerSprite[dirMultiplier()][1], x + 2, y + 8);
         //front hand
-        Assets.playerSprite[0][2].setPosition(x - 6, y);
+        Assets.playerSprite[0][2].setPosition(x + 2, y + 8);
         Assets.playerSprite[0][2].draw(spriteBatch);
     }
 
index 1e531415c63baaefd9a04111ec9e663f5cda544a..335e3c0d2239a450908f325c3b94dbaa38982143 100644 (file)
@@ -21,8 +21,6 @@ public class Assets {
     public static final HashMap<String, TextureRegion> textureRegions = new HashMap<>();
     public static final ArrayMap<String, TouchButton> guiMap = new ArrayMap<>();
     private static final GlyphLayout glyphLayout = new GlyphLayout();
-    public static Sprite sandSprite;
-    public static Sprite gravelSprite;
     static BitmapFont minecraftFont;
 
     private static TextureRegion flippedRegion(Texture texture, int x, int y, int width, int height) {
@@ -41,34 +39,14 @@ public class Assets {
         return sprite;
     }
 
-    private static void loadPlayer() {
-        Texture plTex = new Texture(Gdx.files.internal("mobs/char.png"));
-        //LOOK TO LEFT
-        //head
-        playerSprite[0][0] = flippedSprite(new TextureRegion(plTex, 0, 0, 12, 12));
-        //body
-        playerSprite[0][1] = flippedSprite(new TextureRegion(plTex, 0, 13, 12, 12));
-        //hand
-        playerSprite[0][2] = flippedSprite(new TextureRegion(plTex, 25, 5, 20, 20));
-        //leg
-        playerSprite[0][3] = flippedSprite(new TextureRegion(plTex, 25, 27, 20, 20));
-        //LOOK TO RIGHT
-        //head
-        playerSprite[1][0] = flippedSprite(new TextureRegion(plTex, 13, 0, 12, 12));
-        //body
-        playerSprite[1][1] = flippedSprite(new TextureRegion(plTex, 13, 13, 12, 12));
-        //hand
-        playerSprite[1][2] = flippedSprite(new TextureRegion(plTex, 37, 5, 20, 20));
-        //leg
-        playerSprite[1][3] = flippedSprite(new TextureRegion(plTex, 37, 27, 20, 20));
-    }
-
-    private static void loadPig() {
-        Texture pigTex = new Texture(Gdx.files.internal("mobs/pig.png"));
-        pigSprite[0][0] = flippedSprite(new TextureRegion(pigTex, 0, 0, 25, 12));
-        pigSprite[1][0] = flippedSprite(new TextureRegion(pigTex, 0, 12, 25, 12));
-        pigSprite[0][1] = flippedSprite(new TextureRegion(pigTex, 4, 26, 12, 12));
-        pigSprite[1][1] = flippedSprite(new TextureRegion(pigTex, 16, 26, 12, 12));
+    private static void loadMob(Sprite[][] sprite, String mob) {
+        for (int i = 0; i < sprite.length; i++) {
+            for (int j = 0; j < sprite[i].length; j++) {
+                sprite[i][j] = flippedSprite(new Texture(
+                        Gdx.files.internal("mobs/" + mob + "/" + i + "_" + j + ".png")));
+                sprite[i][j].setOrigin(sprite[i][j].getWidth() / 2, 0);
+            }
+        }
     }
 
     /**
@@ -95,13 +73,11 @@ public class Assets {
     }
 
     public static void load() {
-        loadPlayer();
-        loadPig();
+        loadMob(playerSprite, "char");
+        loadMob(pigSprite, "pig");
         loadJSON();
         minecraftFont = new BitmapFont(Gdx.files.internal("font.fnt"), true);
         minecraftFont.getData().setScale(.375f);
-        sandSprite = flippedSprite(new Texture((Gdx.files.internal("textures/blocks/sand.png"))));
-        gravelSprite = flippedSprite(new Texture((Gdx.files.internal("textures/blocks/gravel.png"))));
     }
 
     /**