DEADSOFTWARE

Add items
authorfred-boy <fred-boy@protonmail.com>
Mon, 10 Sep 2018 17:02:01 +0000 (00:02 +0700)
committerfred-boy <fred-boy@protonmail.com>
Mon, 10 Sep 2018 17:02:01 +0000 (00:02 +0700)
core/src/ru/deadsoftware/cavecraft/game/GameInput.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/Item.java [new file with mode: 0644]

index 7a66d9949b223771e0fb321f87c220fe981dafe8..672c4c957c95eff7129ab2a375e41dd342fa8201 100644 (file)
@@ -144,7 +144,7 @@ public class GameInput {
                 int iy = (int) (screenY - (gameProc.renderer.camera.viewportHeight / 2 - Assets.creativeInv.getRegionHeight() / 2 + 18)) / 18;
                 int item = gameProc.creativeScroll*8+(ix + iy * 8);
                 if (ix>=8 || ix<0 || iy<0 || iy>=5) item=-1;
-                if (item >= 0 && item < Items.BLOCKS.size) {
+                if (item >= 0 && item < Items.ITEMS.size()) {
                     for (int i = 8; i > 0; i--) {
                         gameProc.player.inventory[i] = gameProc.player.inventory[i - 1];
                     }
@@ -157,8 +157,8 @@ public class GameInput {
                     screenX<gameProc.renderer.camera.viewportWidth/2+Assets.invBar.getRegionWidth()/2) {
                 gameProc.invSlot = (int)((screenX-(gameProc.renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2))/20);
             } else if (button == Input.Buttons.RIGHT){
-                gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY,
-                            gameProc.player.inventory[gameProc.invSlot]);
+                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);
index 49fe7056faf70015c50f5828e724c7374052491b..45c62b82beaac999e403bf7fe6ab41ee2407187d 100644 (file)
@@ -59,7 +59,7 @@ public class GameProc implements Serializable{
             renderer = new GameRenderer(this,480,
                     480*((float)GameScreen.getHeight()/GameScreen.getWidth()));
         }
-        maxCreativeScroll = Items.BLOCKS.size/8;
+        maxCreativeScroll = Items.ITEMS.size()/8;
         GameSaver.save(this);
     }
 
@@ -373,6 +373,13 @@ public class GameProc implements Serializable{
         }
     }
 
+    public void useItem(int x, int y, int id, boolean bg) {
+        if (Items.ITEMS.get(id).getType()==0) {
+            if (!bg) world.placeToForeground(x, y, Items.ITEMS.get(id).getBlock());
+            else world.placeToBackground(x, y,  Items.ITEMS.get(id).getBlock());
+        }
+    }
+
     public void update(float delta) {
         RUN_TIME += delta;
 
@@ -406,8 +413,7 @@ public class GameProc implements Serializable{
 
         if (isTouchDown && TimeUtils.timeSinceMillis(touchDownTime) > 500) {
             if (touchDownButton== Input.Buttons.RIGHT) {
-                world.placeToBackground(cursorX, cursorY,
-                        player.inventory[invSlot]);
+                useItem(cursorX, cursorY, player.inventory[invSlot], true);
             } else if (touchDownY< Assets.invBar.getRegionHeight() &&
                     touchDownX>renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 &&
                     touchDownX<renderer.camera.viewportWidth/2+Assets.invBar.getRegionWidth()/2) {
index d8063264b58fb34102d6dc2ed0ce5dc345af613e..1eef325463a41614b6d98714ba21110ffb2e5af5 100644 (file)
@@ -126,15 +126,17 @@ public class GameRenderer extends Renderer {
         spriteBatch.draw(Assets.creativeScroll, x+156,
                 y+18+(gameProc.creativeScroll*(72/gameProc.maxCreativeScroll)));
         for (int i=gameProc.creativeScroll*8; i<gameProc.creativeScroll*8+40; i++) {
-            if (i>0 && i<Items.BLOCKS.size)
-                spriteBatch.draw(Assets.blockTextures[Items.BLOCKS.getValueAt(i).getTexture()],
-                        x+8+((i-gameProc.creativeScroll*8)%8)*18,
-                        y+18+((i-gameProc.creativeScroll*8)/8)*18);
+            if (i>0 && i<Items.ITEMS.size())
+                if (Items.ITEMS.get(i).getType() == 0)
+                    spriteBatch.draw(Assets.blockTextures[Items.ITEMS.get(i).getTexture()],
+                            x+8+((i-gameProc.creativeScroll*8)%8)*18,
+                            y+18+((i-gameProc.creativeScroll*8)/8)*18);
         }
         for (int i=0; i<9; i++) {
             if (gameProc.player.inventory[i]>0)
-                spriteBatch.draw(Assets.blockTextures[Items.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture()],
-                        x+8+i*18, y+Assets.creativeInv.getRegionHeight()-24);
+                if (Items.ITEMS.get(i).getType() == 0)
+                    spriteBatch.draw(Assets.blockTextures[Items.ITEMS.get(i).getTexture()],
+                            x+8+i*18, y+Assets.creativeInv.getRegionHeight()-24);
         }
     }
 
@@ -149,9 +151,10 @@ public class GameRenderer extends Renderer {
         spriteBatch.draw(Assets.invBar, camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2, 0);
         for (int i=0; i<9; i++) {
             if (gameProc.player.inventory[i]>0) {
-                spriteBatch.draw(Assets.blockTextures[Items.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture()],
-                        camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2+3+i*20,
-                        3);
+                if (Items.ITEMS.get(gameProc.player.inventory[i]).getType()==0)
+                    spriteBatch.draw(Assets.blockTextures[Items.ITEMS.get(gameProc.player.inventory[i]).getTexture()],
+                            camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2+3+i*20,
+                            3);
             }
         }
         spriteBatch.draw(Assets.invBarCur,
index cb2f73680fdc5ae9adeac971c07d178f37c305a5..2a8c53252424258ddbdb7f8d78cdb15530a09e48 100644 (file)
@@ -2,10 +2,14 @@ package ru.deadsoftware.cavecraft.game;
 
 import com.badlogic.gdx.utils.ArrayMap;
 import ru.deadsoftware.cavecraft.game.objects.Block;
+import ru.deadsoftware.cavecraft.game.objects.Item;
+
+import java.util.ArrayList;
 
 public class Items {
 
     public static ArrayMap<String, Block> BLOCKS = new ArrayMap<String, Block>();
+    public static ArrayList<Item> ITEMS = new ArrayList<Item>();
 
     public static boolean isFluid(int bl) {
         return (bl == 8 || bl == 9 || bl == 60 || bl == 61 || bl == 62 || bl == 63 || bl == 64 || bl == 65 || bl == 66 || bl == 67);
@@ -23,6 +27,116 @@ public class Items {
         return (bl == 51 || bl == 53 || bl == 54 || bl == 55 || bl == 56 || bl == 58);
     }
 
+    public static void loadItems() {
+        //0
+        ITEMS.add(new Item("Stone", 0, 0, 1));
+        //1
+        ITEMS.add(new Item("Grass", 1, 0, 2));
+        //2
+        ITEMS.add(new Item("Dirt", 2, 0, 3));
+        //3
+        ITEMS.add(new Item("Cobblestone", 3, 0, 4));
+        //4
+        ITEMS.add(new Item("Planks", 4, 0, 5));
+        //5
+        ITEMS.add(new Item("Sapling", 5, 0, 6));
+        //6
+        ITEMS.add(new Item("Bedrock", 6, 0, 7));
+        //7
+        ITEMS.add(new Item("Sand", 9, 0, 10));
+        //8
+        ITEMS.add(new Item("Gravel", 10, 0, 11));
+        //9
+        ITEMS.add(new Item("Golden Ore", 11, 0, 12));
+        //10
+        ITEMS.add(new Item("Iron Ore", 12, 0, 13));
+        //11
+        ITEMS.add(new Item("Coal Ore", 13, 0, 14));
+        //12
+        ITEMS.add(new Item("Wood", 14, 0, 15));
+        //13
+        ITEMS.add(new Item("Leaves", 15, 0, 16));
+        //14
+        ITEMS.add(new Item("Glass", 17, 0, 18));
+        //15
+        ITEMS.add(new Item("Lapis Ore", 18, 0, 19));
+        //16
+        ITEMS.add(new Item("Lapis Block", 19, 0, 20));
+        //17
+        ITEMS.add(new Item("Sandstone", 20, 0, 21));
+        //18
+        ITEMS.add(new Item("Cobweb", 24, 0, 25));
+        //19
+        ITEMS.add(new Item("Tall Grass", 25, 0, 26));
+        //20
+        ITEMS.add(new Item("Dead Bush", 26, 0, 27));
+        //21
+        ITEMS.add(new Item("Bricks", 27, 0, 28));
+        //22
+        ITEMS.add(new Item("Dandelion", 28, 0, 29));
+        //23
+        ITEMS.add(new Item("Rose", 29, 0, 30));
+        //24
+        ITEMS.add(new Item("Mushroom", 30, 0, 31));
+        //25
+        ITEMS.add(new Item("Mushroom", 31, 0, 32));
+        //26
+        ITEMS.add(new Item("White Wool", 32, 0, 33));
+        //27
+        ITEMS.add(new Item("Orange Wool", 33, 0, 34));
+        //28
+        ITEMS.add(new Item("Magenta Wool", 34, 0, 35));
+        //29
+        ITEMS.add(new Item("Light Blue Wool", 35, 0, 36));
+        //30
+        ITEMS.add(new Item("Yellow Wool", 36, 0, 37));
+        //31
+        ITEMS.add(new Item("Lime Wool", 37, 0, 38));
+        //32
+        ITEMS.add(new Item("Pink Wool", 38, 0, 39));
+        //33
+        ITEMS.add(new Item("Gray Wool", 39, 0, 40));
+        //34
+        ITEMS.add(new Item("Light Gray Wool", 40, 0, 41));
+        //35
+        ITEMS.add(new Item("Cyan Wool", 41, 0, 42));
+        //36
+        ITEMS.add(new Item("Purple Wool", 42, 0, 43));
+        //37
+        ITEMS.add(new Item("Blue Wool", 43, 0, 44));
+        //38
+        ITEMS.add(new Item("Brown Wool", 44, 0, 45));
+        //39
+        ITEMS.add(new Item("Green Wool", 45, 0, 46));
+        //40
+        ITEMS.add(new Item("Red Wool", 46, 0, 47));
+        //41
+        ITEMS.add(new Item("Black Wool", 47, 0, 48));
+        //42
+        ITEMS.add(new Item("Golden Block", 48, 0, 49));
+        //43
+        ITEMS.add(new Item("Iron Block", 49, 0, 50));
+        //44
+        ITEMS.add(new Item("Stone Slab", 50, 0, 51));
+        //45
+        ITEMS.add(new Item("Sandstone Slab", 52, 0, 53));
+        //46
+        ITEMS.add(new Item("Wooden Slab", 53, 0, 54));
+        //47
+        ITEMS.add(new Item("Cobblestone Slab", 54, 0, 55));
+        //48
+        ITEMS.add(new Item("Brick Slab", 55, 0, 56));
+        //49
+        ITEMS.add(new Item("Stone Brick", 64, 0, 57));
+        //50
+        ITEMS.add(new Item("Stone Brick Slab", 56, 0, 58));
+        //51
+        ITEMS.add(new Item("Cactus", 57, 0, 59));
+        //52
+        ITEMS.add(new Item("Obsidian", 65, 0, 68));
+
+    }
+
     public static void loadBlocks() {
         //0
         BLOCKS.put("none", null);
@@ -166,6 +280,7 @@ public class Items {
 
     public static void load() {
         loadBlocks();
+        loadItems();
     }
 
 }
diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Item.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Item.java
new file mode 100644 (file)
index 0000000..5e6fdeb
--- /dev/null
@@ -0,0 +1,29 @@
+package ru.deadsoftware.cavecraft.game.objects;
+
+public class Item {
+
+    private int texture, type;
+    private int block;
+    private String name;
+
+    public Item(String name, int texture, int type, int block) {
+        this.name = name;
+        this.texture = texture;
+        this.type = type;
+        this.block = block;
+    }
+
+    public int getTexture() {
+        return texture;
+    }
+    public int getType() {
+        return type;
+    }
+    public int getBlock() {
+        return block;
+    }
+    public String getName() {
+        return name;
+    }
+
+}