DEADSOFTWARE

Add more blocks
authorfred-boy <fred-boy@protonmail.com>
Wed, 25 Apr 2018 12:55:51 +0000 (19:55 +0700)
committerfred-boy <fred-boy@protonmail.com>
Wed, 25 Apr 2018 13:09:02 +0000 (20:09 +0700)
android/assets/terrain.png
core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
core/src/ru/deadsoftware/cavecraft/game/GameWorld.java
core/src/ru/deadsoftware/cavecraft/game/Items.java
core/src/ru/deadsoftware/cavecraft/game/objects/Block.java
core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java
core/src/ru/deadsoftware/cavecraft/misc/Assets.java

index 11be603c04fcd1a53fa7ce91fa8363cd4ae2a20f..28bfb43f168fd1dd8a6593b75a2ec532f4615db1 100644 (file)
Binary files a/android/assets/terrain.png and b/android/assets/terrain.png differ
index 3ffc0aed78dda0c7914330a13d91c098cffc9037..648e785e8d07a96c9de6728124be0bcaac3013a8 100644 (file)
@@ -28,14 +28,19 @@ public class GameRenderer extends Renderer {
         if (maxY>gameProc.world.getHeight()) maxY = gameProc.world.getHeight();
         for (int y=minY; y<maxY; y++) {
             for (int x=minX; x<maxX; x++) {
-                if (gameProc.world.getForeMap(x,y)>0){
-                } else if (gameProc.world.getBackMap(x,y)>0) {
+                if ((gameProc.world.getForeMap(x,y)==0 || Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).transparent)
+                        && gameProc.world.getBackMap(x,y)>0) {
                     spriteBatch.draw(
-                            Items.BLOCKS.getValueAt(gameProc.world.getBackMap(x,y)).getTexture(),
+                            Assets.blockTextures[Items.BLOCKS.getValueAt(gameProc.world.getBackMap(x,y)).getTexture()],
                             x * 16 - camera.position.x,y * 16 - camera.position.y);
                     Assets.shade.setPosition(x * 16 - camera.position.x,y * 16 - camera.position.y);
                     Assets.shade.draw(spriteBatch);
                 }
+                if (gameProc.world.getForeMap(x,y)>0 && Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).background) {
+                    spriteBatch.draw(
+                            Assets.blockTextures[Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture()],
+                            x * 16 - camera.position.x,y * 16 - camera.position.y);
+                }
             }
         }
     }
@@ -51,7 +56,7 @@ public class GameRenderer extends Renderer {
             for (int x=minX; x<maxX; x++) {
                 if (gameProc.world.getForeMap(x,y)>0) {
                     spriteBatch.draw(
-                            Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture(),
+                            Assets.blockTextures[Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture()],
                             x * 16 - camera.position.x,y * 16 - camera.position.y);
                 }
             }
@@ -119,13 +124,13 @@ public class GameRenderer extends Renderer {
                 y+18+(gameProc.creativeScroll*(72/(gameProc.maxCreativeScroll+1))));
         for (int i=gameProc.creativeScroll*40; i<(gameProc.creativeScroll+1)*40; i++) {
             if (i>0 && i<Items.BLOCKS.size)
-                spriteBatch.draw(Items.BLOCKS.getValueAt(i).getTexture(),
+                spriteBatch.draw(Assets.blockTextures[Items.BLOCKS.getValueAt(i).getTexture()],
                         x+8+((i-gameProc.creativeScroll*40)%8)*18,
                         y+18+((i-gameProc.creativeScroll*40)/8)*18);
         }
         for (int i=0; i<9; i++) {
             if (gameProc.player.inventory[i]>0)
-                spriteBatch.draw(Items.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture(),
+                spriteBatch.draw(Assets.blockTextures[Items.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture()],
                         x+8+i*18, y+Assets.creativeInv.getRegionHeight()-24);
         }
     }
@@ -140,7 +145,7 @@ 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(Items.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture(),
+                spriteBatch.draw(Assets.blockTextures[Items.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture()],
                         camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2+3+i*20,
                         3);
             }
index 7885d2e8ea4bf98d5d18a3e237d3b100e950e490..0c3ac52f40fc1804d29017470e315eaffda5ee0c 100644 (file)
@@ -77,7 +77,7 @@ public class GameWorld {
     }
 
     public void placeToBackground(int x, int y, int value) {
-        if (value==0 || (getBackMap(x,y) == 0 && !Items.BLOCKS.getValueAt(value).foreground)) {
+        if (value==0 || (getBackMap(x,y) == 0 && !Items.BLOCKS.getValueAt(value).background)) {
             setBackMap(x,y,value);
         }
     }
index e28062f1177b99d1d498dd128f6838882730a532..93b9a1f8ee1bb03b62646ef09912a960e58cd954 100644 (file)
@@ -10,24 +10,38 @@ public class Items {
 
     public static void loadBlocks() {
         BLOCKS.put("none", null);
-        BLOCKS.put("stone", new Block(0,0,16,16, Assets.blockTextures[0]));
-        BLOCKS.put("grass", new Block(0,0,16,16,Assets.blockTextures[1]));
-        BLOCKS.put("dirt", new Block(0,0,16,16,Assets.blockTextures[2]));
-        BLOCKS.put("cobblestone", new Block(0,0,16,16,Assets.blockTextures[3]));
-        BLOCKS.put("planks", new Block(0,0,16,16,Assets.blockTextures[4]));
-        BLOCKS.put("sapling", new Block(0,0,16,16,Assets.blockTextures[5],false,true));
-        BLOCKS.put("bedrock", new Block(0,0,16,16,Assets.blockTextures[6]));
-        BLOCKS.put("water", new Block(0,0,16,16,Assets.blockTextures[7],false,true));
-        BLOCKS.put("lava", new Block(0,0,16,16,Assets.blockTextures[8],false,true));
-        BLOCKS.put("sand", new Block(0,0,16,16,Assets.blockTextures[9]));
-        BLOCKS.put("gravel", new Block(0,0,16,16,Assets.blockTextures[10]));
-        BLOCKS.put("gold_ore", new Block(0,0,16,16,Assets.blockTextures[11]));
-        BLOCKS.put("iron_ore", new Block(0,0,16,16,Assets.blockTextures[12]));
-        BLOCKS.put("coal_ore", new Block(0,0,16,16,Assets.blockTextures[13]));
-        BLOCKS.put("log", new Block(0,0,16,16,Assets.blockTextures[14]));
-        BLOCKS.put("leaves", new Block(0,0,16,16,Assets.blockTextures[15]));
-        BLOCKS.put("sponge", new Block(0,0,16,16,Assets.blockTextures[16]));
-        BLOCKS.put("glass", new Block(0,0,16,16,Assets.blockTextures[17]));
+        BLOCKS.put("stone", new Block(0));
+        BLOCKS.put("grass", new Block(1));
+        BLOCKS.put("dirt", new Block(2));
+        BLOCKS.put("cobblestone", new Block(3));
+        BLOCKS.put("planks", new Block(4));
+        BLOCKS.put("sapling", new Block(5,false,false,true));
+        BLOCKS.put("bedrock", new Block(6));
+        BLOCKS.put("water", new Block(7,false,false,true));
+        BLOCKS.put("lava", new Block(8,false,false,false));
+        BLOCKS.put("sand", new Block(9));
+        BLOCKS.put("gravel", new Block(10));
+        BLOCKS.put("gold_ore", new Block(11));
+        BLOCKS.put("iron_ore", new Block(12));
+        BLOCKS.put("coal_ore", new Block(13));
+        BLOCKS.put("log", new Block(14));
+        BLOCKS.put("leaves", new Block(15));
+        BLOCKS.put("sponge", new Block(16));
+        BLOCKS.put("glass", new Block(17,true,false,true));
+        BLOCKS.put("lapis_ore", new Block(18));
+        BLOCKS.put("lapis_block", new Block(19));
+        BLOCKS.put("sandstone", new Block(20));
+        BLOCKS.put("noteblock", new Block(21));
+        BLOCKS.put("bed", new Block(0,8,16,8,22,false,true,true));
+        BLOCKS.put("cobweb", new Block(24,false,false,true));
+        BLOCKS.put("tallgrass", new Block(25,false,false,true));
+        BLOCKS.put("deadbush", new Block(26,false,false,true));
+        BLOCKS.put("brick_block", new Block(27));
+        BLOCKS.put("dandelion", new Block(28,false,false,true));
+        BLOCKS.put("rose", new Block(29,false,false,true));
+        BLOCKS.put("brown_mushroom", new Block(30,false,false,true));
+        BLOCKS.put("red_mushroom", new Block(31,false,false,true));
+        BLOCKS.put("wool", new Block(32,false,true,false));
     }
 
     public static void load() {
index a1696f64b340a7c3ed979cf3c3e5b359362dfb0e..4fa47369fd151f2760ea314e58e9eadb2009ec43 100644 (file)
@@ -6,25 +6,30 @@ import com.badlogic.gdx.math.Rectangle;
 public class Block {
 
     private int x,y,w,h;
-    private TextureRegion texture;
+    private int texture;
 
-    public boolean collision, foreground;
+    public boolean collision, background, transparent;
 
-    public Block(int x, int y, int w, int h, TextureRegion texture) {
-        this(x,y,w,h,texture, true, false);
+    public Block(int texture) {
+        this(0,0,16,16,texture, true, false, false);
     }
 
-    public Block(int x, int y, int w, int h, TextureRegion texture, boolean collision, boolean foreground) {
+    public Block(int texture, boolean collision, boolean background, boolean transparent) {
+        this(0,0,16,16,texture, collision, background, transparent);
+    }
+
+    public Block(int x, int y, int w, int h, int texture, boolean collision, boolean background, boolean transparent) {
         this.x = x;
         this.y = y;
         this.w = w;
         this.h = h;
         this.texture = texture;
         this.collision = collision;
-        this.foreground = foreground;
+        this.background = background;
+        this.transparent = transparent;
     }
 
-    public TextureRegion getTexture() {
+    public int getTexture() {
         return texture;
     }
 
index acfad3d6f29b50138b901a9986ad658d7500c7fb..da04d469107decbc21aa517a6a0259b75b05fe60 100644 (file)
@@ -61,7 +61,7 @@ public class MenuRenderer extends Renderer {
         spriteBatch.begin();
         for (int x=0; x<=getWidth()/16; x++)
             for (int y=0; y<=getHeight()/16; y++) {
-                spriteBatch.draw(Items.BLOCKS.get("dirt").getTexture(), x * 16, y * 16);
+                spriteBatch.draw(Assets.blockTextures[Items.BLOCKS.get("dirt").getTexture()], x * 16, y * 16);
                 spriteBatch.draw(Assets.shade,x*16,y*16);
             }
         spriteBatch.draw(Assets.gameLogo, getWidth()/2-Assets.gameLogo.getWidth()/2, 0);
index f3d1226df70edfc4ff838fa1616997821a17dfb3..28f3508d8172b12110ddd5ca6972d9bf2e65e6bd 100644 (file)
@@ -10,7 +10,7 @@ import ru.deadsoftware.cavecraft.CaveGame;
 
 public class Assets {
 
-    public static final int BLOCK_TEXTURES = 18;
+    public static final int BLOCK_TEXTURES = 47;
 
     private static GlyphLayout layout;