DEADSOFTWARE

Add more blocks
authorfred-boy <fred-boy@protonmail.com>
Thu, 12 Apr 2018 10:45:59 +0000 (17:45 +0700)
committerfred-boy <fred-boy@protonmail.com>
Thu, 12 Apr 2018 10:45:59 +0000 (17:45 +0700)
android/assets/terrain.png
android/assets/terrain_mc.png
core/src/ru/deadsoftware/cavecraft/Assets.java
core/src/ru/deadsoftware/cavecraft/Items.java
core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java
core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
core/src/ru/deadsoftware/cavecraft/game/WorldGen.java
core/src/ru/deadsoftware/cavecraft/game/objects/Block.java
core/src/ru/deadsoftware/cavecraft/game/objects/Player.java

index 4a9c27b76710b55e4abe3edcfd09f34fe4fe85a3..821b3e37a80a41caa072e27b032627aecd9c14b1 100644 (file)
Binary files a/android/assets/terrain.png and b/android/assets/terrain.png differ
index d2e3b85cf169e47c81018d16cbae2ba93d0ff6ff..1638c201ff09aca55c677e1463e7dd7be948c088 100644 (file)
Binary files a/android/assets/terrain_mc.png and b/android/assets/terrain_mc.png differ
index 3764a587345a0b5979a21e93730eeed5d2db8298..9d06345da9848da026bf0c9bd46d1f40382a8f18 100644 (file)
@@ -9,7 +9,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
 
 public class Assets {
 
-    public static final int BLOCK_TEXTURES = 3;
+    public static final int BLOCK_TEXTURES = 9;
 
     public static BitmapFont minecraftFont;
 
index 2a4071fd8aa29d6681c02f41cfbaaeead1e081d8..2b2474158bb40582a736230d7e756c18477a7a6d 100644 (file)
@@ -10,8 +10,14 @@ public class Items {
     public static void load() {
         BLOCKS.put("none", null);
         BLOCKS.put("stone", new Block(0,0,16,16,Assets.blockTextures[0]));
-        BLOCKS.put("dirt", new Block(0,0,16,16,Assets.blockTextures[1]));
-        BLOCKS.put("grass", new Block(0,0,16,16,Assets.blockTextures[2]));
+        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));
     }
 
 }
index 3bd467d2ab05ce5ae97f0f9dc7f93efb49e0ead4..2d59d349118d0da781cc7d703aa9a2811768626a 100644 (file)
@@ -4,6 +4,7 @@ import com.badlogic.gdx.math.MathUtils;
 import com.badlogic.gdx.math.Rectangle;
 import com.badlogic.gdx.math.Vector2;
 import com.badlogic.gdx.math.Vector3;
+import ru.deadsoftware.cavecraft.Items;
 import ru.deadsoftware.cavecraft.game.mobs.Mob;
 import ru.deadsoftware.cavecraft.game.objects.Player;
 
@@ -21,22 +22,24 @@ public class GamePhysics {
     }
 
     private boolean checkJump(Rectangle rect, int dir) {
-        int bl;
+        int bl = 0;
         switch (dir) {
             case 0:
-                bl = gameProc.world.getForeMap(
+                if ((int)((rect.x+(rect.width/2))/16) - 1>=0)
+                    bl = gameProc.world.getForeMap(
                         (int)((rect.x+(rect.width/2))/16) - 1,
                         (int)(rect.y/16)+1);
                 break;
             case 1:
-                bl = gameProc.world.getForeMap(
+                if ((int)((rect.x+(rect.width/2))/16) + 1<gameProc.world.getWidth())
+                    bl = gameProc.world.getForeMap(
                         (int)((rect.x+(rect.width/2))/16) + 1,
                         (int)(rect.y/16)+1);
                 break;
             default:
                 bl=0;
         }
-        return (bl!=0);
+        return (bl>0 && Items.BLOCKS.getValueAt(bl).collision);
     }
 
     private boolean checkColl(Rectangle rect) {
@@ -47,7 +50,7 @@ public class GamePhysics {
         bl[3] = gameProc.world.getForeMap(((int)(rect.x+rect.width-1)/16), ((int)(rect.y+rect.height/2)/16));
         bl[4] = gameProc.world.getForeMap(((int)(rect.x)/16), ((int)(rect.y+rect.height-1)/16));
         bl[5] = gameProc.world.getForeMap(((int)(rect.x+rect.width-1)/16), ((int)(rect.y+(rect.height-1))/16));
-        for (int b: bl) if (b>0) {
+        for (int b: bl) if (b>0 && Items.BLOCKS.getValueAt(b).collision) {
             return true;
         }
         return false;
index cc3bcdee8c9f849e89f1d8184bb68b397c4660e8..84060ca2b804d6749702257f1faa5aa2cf8b8829 100644 (file)
@@ -61,7 +61,8 @@ public class GameRenderer {
         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) {
+                if (gameProc.world.getForeMap(x,y)>0 &&
+                        !Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).foreground) {
                     spriteBatch.draw(
                             Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture(),
                             x * 16 - camera.position.x,y * 16 - camera.position.y);
@@ -76,6 +77,27 @@ public class GameRenderer {
         }
     }
 
+    private void drawWorldForeground(){
+        int minX = (int) (camera.position.x/16);
+        int minY = (int) (camera.position.y/16);
+        int maxX = (int) ((camera.position.x+camera.viewportWidth)/16)+1;
+        int maxY = (int) ((camera.position.y+camera.viewportHeight)/16)+1;
+        if (minX<0) minX=0;
+        if (minY<0) minY=0;
+        if (maxX>gameProc.world.getWidth()) maxX = gameProc.world.getWidth();
+        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 &&
+                        Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).foreground) {
+                    spriteBatch.draw(
+                            Items.BLOCKS.getValueAt(gameProc.world.getForeMap(x,y)).getTexture(),
+                            x * 16 - camera.position.x,y * 16 - camera.position.y);
+                }
+            }
+        }
+    }
+
     private void drawMob(Mob mob) {
         mob.draw(spriteBatch,
                 mob.position.x-camera.position.x, mob.position.y-camera.position.y);
@@ -121,7 +143,7 @@ public class GameRenderer {
 
     private void drawGUI() {
         spriteBatch.draw(Assets.invBar, camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2, 0);
-        for (int i=0; i<8; i++) {
+        for (int i=0; i<9; i++) {
             if (gameProc.player.inventory[i]>0) {
                 spriteBatch.draw(Items.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture(),
                         camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2+3+i*20,
@@ -155,6 +177,7 @@ public class GameRenderer {
         drawWorld();
         for (Mob mob : gameProc.mobs) drawMob(mob);
         drawPlayer(gameProc.player);
+        drawWorldForeground();
         drawGUI();
         spriteBatch.end();
 
@@ -175,7 +198,7 @@ public class GameRenderer {
         drawString("Y: "+(int)(gameProc.player.position.y/16), 0, 60);
         drawString("Block: "+
                 Items.BLOCKS.keys().toArray().get(gameProc.world.getForeMap(
-                        (int)(gameProc.player.position.x/16),
+                        (int)((gameProc.player.position.x+gameProc.player.texWidth/2)/16),
                         (int)(gameProc.player.position.y/16+2))),
                 0, 80);
         fontBatch.end();
index 5bc94ff2944f5c0f642227f188524d473142c86a..7e676f82f8bbafd59df33cb4346b9abb05cc6ce9 100644 (file)
@@ -43,14 +43,17 @@ public class WorldGen {
             dirtH = 4+rand.nextInt(2);
             for (int y = height- hMap[x]; y<height; y++) {
                 if (y==height- hMap[x]) {
-                    foreMap[x][y] = 3;
-                    backMap[x][y] = 3;
-                } else if (y<height-hMap[x]+dirtH) {
                     foreMap[x][y] = 2;
                     backMap[x][y] = 2;
-                } else {
+                } else if (y<height-hMap[x]+dirtH) {
+                    foreMap[x][y] = 3;
+                    backMap[x][y] = 3;
+                } else if (y<height-1){
                     foreMap[x][y] = 1;
                     backMap[x][y] = 1;
+                } else {
+                    foreMap[x][y] = 7;
+                    backMap[x][y] = 7;
                 }
             }
         }
index e888b212fe3d0b7d8ac0b9690dba9757022eac01..77810e95084e6ef1b1f8c54a0bc588b53faadfa4 100644 (file)
@@ -8,9 +8,17 @@ public class Block {
     private Rectangle rect;
     private TextureRegion texture;
 
+    public boolean collision, foreground;
+
     public Block(int x, int y, int w, int h, TextureRegion texture) {
+        this(x,y,w,h,texture, true, false);
+    }
+
+    public Block(int x, int y, int w, int h, TextureRegion texture, boolean collision, boolean foreground) {
         rect = new Rectangle(x,y,w,h);
         this.texture = texture;
+        this.collision = collision;
+        this.foreground = foreground;
     }
 
     public TextureRegion getTexture() {
index 1dc516bdd9e761b57124c18d6777df4364d7418d..18188690f75f33a35dd2445e6ff3086681a5bd51 100644 (file)
@@ -24,6 +24,12 @@ public class Player {
         inventory[0] = 1;
         inventory[1] = 2;
         inventory[2] = 3;
+        inventory[3] = 4;
+        inventory[4] = 5;
+        inventory[5] = 6;
+        inventory[6] = 7;
+        inventory[7] = 8;
+        inventory[8] = 9;
     }
 
     public Rectangle getRect() {