DEADSOFTWARE

Add drop and block breaking
authorfred-boy <fred-boy@protonmail.com>
Fri, 28 Sep 2018 11:49:59 +0000 (18:49 +0700)
committerfred-boy <fred-boy@protonmail.com>
Fri, 28 Sep 2018 11:49:59 +0000 (18:49 +0700)
android/assets/break.png [new file with mode: 0644]
android/assets/items.png
core/src/ru/deadsoftware/cavecraft/game/GameInput.java
core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
core/src/ru/deadsoftware/cavecraft/game/GameProc.java
core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
core/src/ru/deadsoftware/cavecraft/game/Items.java
core/src/ru/deadsoftware/cavecraft/game/objects/Block.java
core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java [new file with mode: 0644]
core/src/ru/deadsoftware/cavecraft/misc/Assets.java

diff --git a/android/assets/break.png b/android/assets/break.png
new file mode 100644 (file)
index 0000000..1af7a40
Binary files /dev/null and b/android/assets/break.png differ
index cecb5e8cc63369f91734298023b6aa0a34898973..d4ca336da12bf638f97aee84ed09210ef7adac54 100644 (file)
Binary files a/android/assets/items.png and b/android/assets/items.png differ
index 672c4c957c95eff7129ab2a375e41dd342fa8201..0f6c399c2ff60668c412fb0bdd1062964537b1e4 100644 (file)
@@ -51,6 +51,7 @@ public class GameInput {
                     gameProc.cursorY++;
                     break;
             }
+            gameProc.blockDmg = 0;
         }
     }
 
@@ -160,12 +161,7 @@ public class GameInput {
                 gameProc.useItem(gameProc.cursorX, gameProc.cursorY,
                             gameProc.player.inventory[gameProc.invSlot], false);
             } else if (button == Input.Buttons.LEFT) {
-                if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY) > 0) {
-                    gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 0);
-                } else if (gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY) > 0) {
-                    gameProc.world.placeToBackground(gameProc.cursorX, gameProc.cursorY, 0);
-                }
-
+                gameProc.blockDmg = 0;
             }
         }
         gameProc.isTouchDown = false;
index fdf1206371935e23a848428fca23f3d594c61b33..c387bab3f84e816b87007acbd6b4aaa7b2bfe593 100644 (file)
@@ -7,6 +7,7 @@ import com.badlogic.gdx.math.Rectangle;
 import com.badlogic.gdx.math.Vector2;
 import ru.deadsoftware.cavecraft.CaveGame;
 import ru.deadsoftware.cavecraft.game.mobs.Mob;
+import ru.deadsoftware.cavecraft.game.objects.Drop;
 import ru.deadsoftware.cavecraft.game.objects.Player;
 
 import java.util.Iterator;
@@ -67,6 +68,16 @@ public class GamePhysics {
         return gameProc.world.getForeMap((int)(rect.x+rect.width/2)/16, (int)(rect.y+rect.height/8*7)/16);
     }
 
+    private void dropPhy(Drop drop) {
+        if (drop.move.y < 9) drop.move.y += gravity.y/4;
+        drop.position.add(drop.move);
+        drop.position.y = MathUtils.round(drop.position.y);
+        while (checkColl(drop.getRect())) {
+            drop.position.y--;
+            drop.move.y = 0;
+        }
+    }
+
     private void playerPhy(Player pl) {
         pl.position.add(pl.moveY);
         if (checkColl(pl.getRect())) {
@@ -170,6 +181,7 @@ public class GamePhysics {
 }
 
     public void update(float delta) {
+        for (Drop drop : gameProc.drops) dropPhy(drop);
         for (Mob mob : gameProc.mobs) {
             mob.ai();
             mobPhy(mob);
index ddeac68a9f9d195f46630c98c1896c829036f5d8..25658c165421870f9d3868e08f16f4bd96a2e847 100644 (file)
@@ -9,6 +9,7 @@ import ru.deadsoftware.cavecraft.game.mobs.FallingGravel;
 import ru.deadsoftware.cavecraft.game.mobs.FallingSand;
 import ru.deadsoftware.cavecraft.game.mobs.Mob;
 import ru.deadsoftware.cavecraft.game.mobs.Pig;
+import ru.deadsoftware.cavecraft.game.objects.Drop;
 import ru.deadsoftware.cavecraft.game.objects.Player;
 import ru.deadsoftware.cavecraft.misc.AppState;
 import ru.deadsoftware.cavecraft.misc.Assets;
@@ -22,11 +23,11 @@ public class GameProc implements Serializable{
 
     public static boolean DO_UPD = false;
     public static int UPD_X = -1, UPD_Y = -1;
-    public static int FUPD_X, FUPD_Y;
 
     public Player player;
 
     public ArrayList<Mob> mobs;
+    public ArrayList<Drop> drops;
 
     public transient GameWorld world;
     public transient GameRenderer renderer;
@@ -36,6 +37,7 @@ public class GameProc implements Serializable{
     public int invSlot;
     public int ctrlMode;
     public int creativeScroll, maxCreativeScroll;
+    public int blockDmg = 0;
 
     public boolean isTouchDown, isKeyDown, swim;
     public int touchDownX, touchDownY, keyDownCode;
@@ -46,6 +48,7 @@ public class GameProc implements Serializable{
         world = new GameWorld();
         world.generate(1024,256);
         player = new Player(world.getSpawnPoint());
+        drops = new ArrayList<Drop>();
         mobs = new ArrayList<Mob>();
         for (int i=0; i<16; i++) {
             mobs.add(new Pig(i*256, 196*16));
@@ -79,6 +82,7 @@ public class GameProc implements Serializable{
     }
 
     private void moveCursor() {
+        int pastX = cursorX, pastY = cursorY;
         if (ctrlMode == 0 && CaveGame.TOUCH) {
             cursorX = (int) (player.position.x + player.texWidth / 2) / 16;
             if (player.dir == 0) cursorX--;
@@ -103,6 +107,7 @@ public class GameProc implements Serializable{
                     (renderer.camera.viewportWidth/GameScreen.getWidth())+renderer.camera.position.x)<0)
                 cursorX--;
         }
+        if (pastX!=cursorX || pastY!=cursorY) blockDmg = 0;
     }
 
     private void checkCursorBounds() {
@@ -397,29 +402,33 @@ public class GameProc implements Serializable{
             }
         }
 
-        updateFluids(FUPD_X, FUPD_Y);
-        FUPD_X++;
-        if (FUPD_X>=(int)(renderer.camera.position.x+renderer.camera.viewportWidth)/16+1) {
-            FUPD_X = (int) renderer.camera.position.x / 16 - 1;
-            FUPD_Y++;
-            if (FUPD_Y>=(int)(renderer.camera.position.y+renderer.camera.viewportHeight)/16+1) {
-                FUPD_Y = (int) renderer.camera.position.y / 16 - 1;
-            }
-        }
-
         physics.update(delta);
         moveCursor();
         checkCursorBounds();
 
+        if (isTouchDown && touchDownButton==Input.Buttons.LEFT) {
+            if (world.getForeMap(cursorX, cursorY) > 0 &&
+                    Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getHp()>=0){// || world.getBackMap(cursorX, cursorY) > 0) {
+                blockDmg++;
+                if (blockDmg>=Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getHp()) {
+                    if (Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getDrop()>0)
+                        drops.add(new Drop(cursorX*16+4, cursorY*16+4, Items.BLOCKS.getValueAt(world.getForeMap(cursorX, cursorY)).getDrop()));
+                    world.placeToForeground(cursorX, cursorY, 0);
+                    blockDmg=0;
+                }
+            }
+        }
+
         if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) {
             if (touchDownButton== Input.Buttons.RIGHT) {
                 useItem(cursorX, cursorY, player.inventory[invSlot], true);
+                isTouchDown = false;
             } else if (touchDownY< Assets.invBar.getRegionHeight() &&
                     touchDownX>renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 &&
                     touchDownX<renderer.camera.viewportWidth/2+Assets.invBar.getRegionWidth()/2) {
                 CaveGame.STATE = AppState.GAME_CREATIVE_INV;
+                isTouchDown = false;
             }
-            isTouchDown = false;
         }
     }
 
index ee9d6d4d9d68c83542c76877831bfc851259e784..3d3a8f60b8a67b6999e81a097bdacb5dcf939d44 100644 (file)
@@ -9,6 +9,7 @@ import com.badlogic.gdx.math.Vector2;
 import ru.deadsoftware.cavecraft.CaveGame;
 import ru.deadsoftware.cavecraft.GameScreen;
 import ru.deadsoftware.cavecraft.game.mobs.Mob;
+import ru.deadsoftware.cavecraft.game.objects.Drop;
 import ru.deadsoftware.cavecraft.game.objects.Player;
 import ru.deadsoftware.cavecraft.misc.Assets;
 import ru.deadsoftware.cavecraft.misc.Renderer;
@@ -76,6 +77,18 @@ public class GameRenderer extends Renderer {
                 mob.position.x-camera.position.x+gameProc.world.getWidth()*16, mob.position.y-camera.position.y);
     }
 
+    private void drawDrop(Drop drop) {
+        switch (Items.ITEMS.get(drop.getId()).getType()) {
+            case 0:
+                Assets.blockTextures[Items.ITEMS.get(drop.getId()).getTexture()].setPosition(drop.position.x-camera.position.x-gameProc.world.getWidth()*16, drop.position.y-camera.position.y);
+                Assets.blockTextures[Items.ITEMS.get(drop.getId()).getTexture()].draw(spriteBatch);
+                Assets.blockTextures[Items.ITEMS.get(drop.getId()).getTexture()].setPosition(drop.position.x-camera.position.x, drop.position.y-camera.position.y);
+                Assets.blockTextures[Items.ITEMS.get(drop.getId()).getTexture()].draw(spriteBatch);
+                Assets.blockTextures[Items.ITEMS.get(drop.getId()).getTexture()].setPosition(drop.position.x-camera.position.x+gameProc.world.getWidth()*16, drop.position.y-camera.position.y);
+                Assets.blockTextures[Items.ITEMS.get(drop.getId()).getTexture()].draw(spriteBatch);
+        }
+    }
+
     private void drawPlayer(Player pl) {
         if (!pl.moveX.equals(Vector2.Zero) || Assets.playerSprite[0][2].getRotation()!=0) {
             Assets.playerSprite[0][2].rotate(Player.ANIM_SPEED);
@@ -177,6 +190,13 @@ public class GameRenderer extends Renderer {
     }
 
     private void drawGUI() {
+        if (gameProc.blockDmg > 0) {
+            spriteBatch.draw(Assets.wreck[
+                            10*gameProc.blockDmg/
+                                    Items.BLOCKS.getValueAt(gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY)).getHp()],
+                    gameProc.cursorX*16-camera.position.x,
+                    gameProc.cursorY*16-camera.position.y);
+        }
         if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY)>0 ||
                 gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY)>0 ||
                 gameProc.ctrlMode==1 ||
@@ -224,6 +244,7 @@ public class GameRenderer extends Renderer {
         drawWorldBackground();
         drawPlayer(gameProc.player);
         for (Mob mob : gameProc.mobs) drawMob(mob);
+        for (Drop drop : gameProc.drops) drawDrop(drop);
         drawWorldForeground();
         drawGUI();
     }
@@ -250,7 +271,8 @@ public class GameRenderer extends Renderer {
             drawString("X: "+(int)(gameProc.player.position.x/16),0, 10);
             drawString("Y: "+(int)(gameProc.player.position.y/16),0, 20);
             drawString("Mobs: "+gameProc.mobs.size(), 0, 30);
-            drawString("Block: "+Items.BLOCKS.getKeyAt(gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY)), 0, 40);
+            drawString("Drops: "+gameProc.drops.size(), 0, 40);
+            drawString("Block: "+Items.BLOCKS.getKeyAt(gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY)), 0, 50);
         }
 
         spriteBatch.end();
index db32ad13b5d25e7bb86f85672121ac6a99365c95..690d5ac3c99b7e3a50f97dd72f64dc779ca15ca6 100644 (file)
@@ -146,6 +146,16 @@ public class Items {
         ITEMS.add(new Item("Diamond Sword", 3, 1));
         //58
         ITEMS.add(new Item("Golden Sword", 4, 1));
+        //59
+        ITEMS.add(new Item("Wooden Shovel", 5, 1));
+        //60
+        ITEMS.add(new Item("Stone Shovel", 6, 1));
+        //61
+        ITEMS.add(new Item("Iron Shovel", 7, 1));
+        //62
+        ITEMS.add(new Item("Diamond Shovel", 8, 1));
+        //63
+        ITEMS.add(new Item("Golden Shovel", 9, 1));
 
     }
 
@@ -153,141 +163,141 @@ public class Items {
         //0
         BLOCKS.put("none", null);
         //1
-        BLOCKS.put("stone", new Block(0));
+        BLOCKS.put("stone", new Block(0, 450, 4));
         //2
-        BLOCKS.put("grass", new Block(1));
+        BLOCKS.put("grass", new Block(1, 54, 3));
         //3
-        BLOCKS.put("dirt", new Block(2));
+        BLOCKS.put("dirt", new Block(2, 45, 3));
         //4
-        BLOCKS.put("cobblestone", new Block(3));
+        BLOCKS.put("cobblestone", new Block(3, 600, 4));
         //5
-        BLOCKS.put("planks", new Block(4));
+        BLOCKS.put("planks", new Block(4, 180, 5));
         //6
-        BLOCKS.put("sapling", new Block(5,false,false,true));
+        BLOCKS.put("sapling", new Block(5,0,6,false,false,true));
         //7
-        BLOCKS.put("bedrock", new Block(6));
+        BLOCKS.put("bedrock", new Block(6,-1,7));
         //8
-        BLOCKS.put("water", new Block(7,false,false,true));
+        BLOCKS.put("water", new Block(7,-1,0,false,false,true));
         //9
-        BLOCKS.put("lava", new Block(8,false,false,false));
+        BLOCKS.put("lava", new Block(8,-1,0,false,false,false));
         //10
-        BLOCKS.put("sand", new Block(9));
+        BLOCKS.put("sand", new Block(9, 45,8));
         //11
-        BLOCKS.put("gravel", new Block(10));
+        BLOCKS.put("gravel", new Block(10, 54,9));
         //12
-        BLOCKS.put("gold_ore", new Block(11));
+        BLOCKS.put("gold_ore", new Block(11, 900,10));
         //13
-        BLOCKS.put("iron_ore", new Block(12));
+        BLOCKS.put("iron_ore", new Block(12, 900,11));
         //14
-        BLOCKS.put("coal_ore", new Block(13));
+        BLOCKS.put("coal_ore", new Block(13, 900,0));
         //15
-        BLOCKS.put("log", new Block(14));
+        BLOCKS.put("log", new Block(14, 180,13));
         //16
-        BLOCKS.put("leaves", new Block(15));
+        BLOCKS.put("leaves", new Block(15, 21,0));
         //17
-        BLOCKS.put("sponge", new Block(16));
+        BLOCKS.put("sponge", new Block(16, 54,0));
         //18
-        BLOCKS.put("glass", new Block(17,true,false,true));
+        BLOCKS.put("glass", new Block(17, 27,0,true,false,true));
         //19
-        BLOCKS.put("lapis_ore", new Block(18));
+        BLOCKS.put("lapis_ore", new Block(18, 900,0));
         //20
-        BLOCKS.put("lapis_block", new Block(19));
+        BLOCKS.put("lapis_block", new Block(19, 900,17));
         //21
-        BLOCKS.put("sandstone", new Block(20));
+        BLOCKS.put("sandstone", new Block(20, 240,18));
         //22
-        BLOCKS.put("noteblock", new Block(21));
+        BLOCKS.put("noteblock", new Block(21, 75,0));
         //23
-        BLOCKS.put("bed_l", new Block(22,false,true,true));
+        BLOCKS.put("bed_l", new Block(22, 21,0,false,true,true));
         //24
-        BLOCKS.put("bed_r", new Block(23, false,true, true));
+        BLOCKS.put("bed_r", new Block(23, 21,0, false,true, true));
         //25
-        BLOCKS.put("cobweb", new Block(24,false,false,true));
+        BLOCKS.put("cobweb", new Block(24, 1200,0,false,false,true));
         //26
-        BLOCKS.put("tallgrass", new Block(25,false,false,true));
+        BLOCKS.put("tallgrass", new Block(25, 0,0,false,false,true));
         //27
-        BLOCKS.put("deadbush", new Block(26,false,false,true));
+        BLOCKS.put("deadbush", new Block(26, 0,0,false,false,true));
         //28
-        BLOCKS.put("brick_block", new Block(27));
+        BLOCKS.put("brick_block", new Block(27, 600,22));
         //29
-        BLOCKS.put("dandelion", new Block(28,false,false,true));
+        BLOCKS.put("dandelion", new Block(28, 0,23,false,false,true));
         //30
-        BLOCKS.put("rose", new Block(29,false,false,true));
+        BLOCKS.put("rose", new Block(29, 0,24,false,false,true));
         //31
-        BLOCKS.put("brown_mushroom", new Block(30,false,false,true));
+        BLOCKS.put("brown_mushroom", new Block(30, 0,25,false,false,true));
         //32
-        BLOCKS.put("red_mushroom", new Block(31,false,false,true));
+        BLOCKS.put("red_mushroom", new Block(31, 0,26,false,false,true));
         //33
-        BLOCKS.put("wool_while", new Block(32,true,false,false));
+        BLOCKS.put("wool_while", new Block(32, 75,27,true,false,false));
         //34
-        BLOCKS.put("wool_orange", new Block(33,true,false,false));
+        BLOCKS.put("wool_orange", new Block(33, 75,28,true,false,false));
         //35
-        BLOCKS.put("wool_magenta", new Block(34,true,false,false));
+        BLOCKS.put("wool_magenta", new Block(34, 75,29,true,false,false));
         //36
-        BLOCKS.put("wool_lightblue", new Block(35,true,false,false));
+        BLOCKS.put("wool_lightblue", new Block(35, 75,30,true,false,false));
         //37
-        BLOCKS.put("wool_yellow", new Block(36,true,false,false));
+        BLOCKS.put("wool_yellow", new Block(36, 75,31,true,false,false));
         //38
-        BLOCKS.put("wool_lime", new Block(37,true,false,false));
+        BLOCKS.put("wool_lime", new Block(37, 75,32,true,false,false));
         //39
-        BLOCKS.put("wool_pink", new Block(38,true,false,false));
+        BLOCKS.put("wool_pink", new Block(38, 75,33,true,false,false));
         //40
-        BLOCKS.put("wool_gray", new Block(39,true,false,false));
+        BLOCKS.put("wool_gray", new Block(39, 75,34,true,false,false));
         //41
-        BLOCKS.put("wool_lightgray", new Block(40,true,false,false));
+        BLOCKS.put("wool_lightgray", new Block(40, 75,35,true,false,false));
         //42
-        BLOCKS.put("wool_cyan", new Block(41,true,false,false));
+        BLOCKS.put("wool_cyan", new Block(41, 75,36,true,false,false));
         //43
-        BLOCKS.put("wool_purple", new Block(42,true,false,false));
+        BLOCKS.put("wool_purple", new Block(42, 75,37,true,false,false));
         //44
-        BLOCKS.put("wool_blue", new Block(43,true,false,false));
+        BLOCKS.put("wool_blue", new Block(43, 75,38,true,false,false));
         //45
-        BLOCKS.put("wool_brown", new Block(44,true,false,false));
+        BLOCKS.put("wool_brown", new Block(44, 75,39,true,false,false));
         //46
-        BLOCKS.put("wool_green", new Block(45,true,false,false));
+        BLOCKS.put("wool_green", new Block(45, 75,40,true,false,false));
         //47
-        BLOCKS.put("wool_red", new Block(46,true,false,false));
+        BLOCKS.put("wool_red", new Block(46, 75,41,true,false,false));
         //48
-        BLOCKS.put("wool_black", new Block(47,true,false,false));
+        BLOCKS.put("wool_black", new Block(47, 75,42,true,false,false));
         //49
-        BLOCKS.put("gold_block", new Block(48));
+        BLOCKS.put("gold_block", new Block(48, 900,43));
         //50
-        BLOCKS.put("iron_block", new Block(49));
+        BLOCKS.put("iron_block", new Block(49, 1500,44));
         //51
-        BLOCKS.put("stone_slab", new Block(0, 8, 16,8, 50, true, false, true));
+        BLOCKS.put("stone_slab", new Block(0, 8, 16,8, 50, 600,45, true, false, true));
         //52
-        BLOCKS.put("double_stone_slab", new Block(51));
+        BLOCKS.put("double_stone_slab", new Block(51, 600,45));
         //53
-        BLOCKS.put("sandstone_slab", new Block(0, 8, 16,8, 52, true, false, true));
+        BLOCKS.put("sandstone_slab", new Block(0, 8, 16,8, 52, 600,46, true, false, true));
         //54
-        BLOCKS.put("wooden_slab", new Block(0, 8, 16,8, 53, true, false, true));
+        BLOCKS.put("wooden_slab", new Block(0, 8, 16,8, 53, 180,47, true, false, true));
         //55
-        BLOCKS.put("cobblestone_slab", new Block(0, 8, 16,8, 54, true, false, true));
+        BLOCKS.put("cobblestone_slab", new Block(0, 8, 16,8, 54, 600,48, true, false, true));
         //56
-        BLOCKS.put("brick_slab", new Block(0, 8, 16,8, 55, true, false, true));
+        BLOCKS.put("brick_slab", new Block(0, 8, 16,8, 55, 600,49, true, false, true));
         //57
-        BLOCKS.put("stonebrick", new Block(64));
+        BLOCKS.put("stonebrick", new Block(64, 450,50));
         //58
-        BLOCKS.put("stone_brick_slab", new Block(0, 8, 16,8, 56, true, false, true));
+        BLOCKS.put("stone_brick_slab", new Block(0, 8, 16,8, 56, 450,51, true, false, true));
         //59
-        BLOCKS.put("cactus", new Block(1, 0, 14, 16, 57, true, false, true));
+        BLOCKS.put("cactus", new Block(1, 0, 14, 16, 57, 39,52, true, false, true));
         //60
-        BLOCKS.put("water_16", new Block(7,false,false,true));
+        BLOCKS.put("water_16", new Block(7, -1,0,false,false,true));
         //61
-        BLOCKS.put("water_12", new Block(58,false,false,true));
+        BLOCKS.put("water_12", new Block(58, -1,0,false,false,true));
         //62
-        BLOCKS.put("water_8", new Block(59,false,false,true));
+        BLOCKS.put("water_8", new Block(59, -1,0,false,false,true));
         //63
-        BLOCKS.put("water_4", new Block(60,false,false,true));
+        BLOCKS.put("water_4", new Block(60, -1,0,false,false,true));
         //64
-        BLOCKS.put("lava_16", new Block(8,false,false,true));
+        BLOCKS.put("lava_16", new Block(8, -1,0,false,false,true));
         //65
-        BLOCKS.put("lava_12", new Block(61,false,false,true));
+        BLOCKS.put("lava_12", new Block(61, -1,0,false,false,true));
         //66
-        BLOCKS.put("lava_8", new Block(62,false,false,true));
+        BLOCKS.put("lava_8", new Block(62, -1,0,false,false,true));
         //67
-        BLOCKS.put("lava_4", new Block(63,false,false,true));
+        BLOCKS.put("lava_4", new Block(63, -1,0,false,false,true));
         //68
-        BLOCKS.put("obsidian", new Block(65));
+        BLOCKS.put("obsidian", new Block(65, 1500,53));
     }
 
     public static void load() {
index 44619f0654f3c9e2a22adbee85e66e28037962ba..5d2814e7f0e1c26603c763390989819237c26685 100644 (file)
@@ -1,29 +1,31 @@
 package ru.deadsoftware.cavecraft.game.objects;
 
-import com.badlogic.gdx.graphics.g2d.TextureRegion;
 import com.badlogic.gdx.math.Rectangle;
 
 public class Block {
 
     private int x,y,w,h;
     private int texture;
+    private int hp, drop;
 
     public boolean collision, background, transparent;
 
-    public Block(int texture) {
-        this(0,0,16,16,texture, true, false, false);
+    public Block(int texture, int hp, int drop) {
+        this(0,0,16,16,texture, hp, drop, true, false, false);
     }
 
-    public Block(int texture, boolean collision, boolean background, boolean transparent) {
-        this(0,0,16,16,texture, collision, background, transparent);
+    public Block(int texture, int hp, int drop, boolean collision, boolean background, boolean transparent) {
+        this(0,0,16,16,texture, hp, drop, collision, background, transparent);
     }
 
-    public Block(int x, int y, int w, int h, int texture, boolean collision, boolean background, boolean transparent) {
+    public Block(int x, int y, int w, int h, int texture, int hp, int drop, boolean collision, boolean background, boolean transparent) {
         this.x = x;
         this.y = y;
         this.w = w;
         this.h = h;
         this.texture = texture;
+        this.hp = hp;
+        this.drop = drop;
         this.collision = collision;
         this.background = background;
         this.transparent = transparent;
@@ -33,6 +35,14 @@ public class Block {
         return texture;
     }
 
+    public int getHp() {
+        return hp;
+    }
+
+    public int getDrop() {
+        return drop;
+    }
+
     public Rectangle getRect(int x, int y) {
         x*=16;
         y*=16;
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Drop.java
new file mode 100644 (file)
index 0000000..5ff36e4
--- /dev/null
@@ -0,0 +1,35 @@
+package ru.deadsoftware.cavecraft.game.objects;
+
+import com.badlogic.gdx.math.Rectangle;
+import com.badlogic.gdx.math.Vector2;
+
+import java.io.Serializable;
+
+public class Drop implements Serializable {
+    private int id;
+    public Vector2 move, position;
+
+    public static void pickUpDrop(Player pl, int id) {
+        for (int i = 0; i < pl.inventory.length; i++) {
+            if (pl.inventory[i] == 0) {
+                pl.inventory[i] = id;
+                break;
+            }
+        }
+    }
+
+    public Drop(float x, float y, int id) {
+        this.id = id;
+        position = new Vector2(x, y);
+        move = new Vector2(0, -1);
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public Rectangle getRect() {
+        return new Rectangle(position.x, position.y, 8, 8);
+    }
+
+}
index 14575a37ad1b41ef4b752461cace75149eef5fb4..e28c322d3732bb9228b6f1c2ae6c3f48a32be667 100644 (file)
@@ -11,7 +11,7 @@ import ru.deadsoftware.cavecraft.CaveGame;
 public class Assets {
 
     public static final int BLOCK_TEXTURES = 66;
-    public static final int ITEM_TEXTURES = 5;
+    public static final int ITEM_TEXTURES = 10;
 
     private static GlyphLayout layout;
 
@@ -41,6 +41,9 @@ public class Assets {
     public static TextureRegion invBarCur;
     public static TextureRegion guiCur;
 
+    public static Texture wreckTexture;
+    public static TextureRegion[] wreck = new TextureRegion[10];
+
     public static Texture creativeTexture;
     public static TextureRegion creativeInv;
     public static TextureRegion creativeScroll;
@@ -124,6 +127,11 @@ public class Assets {
         creativeScroll = new TextureRegion(creativeTexture, 3, 137, 12, 15);
         creativeScroll.flip(false, true);
 
+        wreckTexture = new Texture(Gdx.files.internal("break.png"));
+        for (int i=0; i<10; i++) {
+            wreck[i] = new TextureRegion(wreckTexture, 16*i, 0, 16, 16);
+        }
+
         if (CaveGame.TOUCH) {
             touchGui = new Texture(Gdx.files.internal("touch_gui.png"));
             for (int i = 0; i < 4; i++) {