From: fred-boy Date: Thu, 12 Apr 2018 10:45:59 +0000 (+0700) Subject: Add more blocks X-Git-Tag: alpha0.1~13 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=3170dad22d4643ae39e66a0d6a445df198418e73;p=cavedroid.git Add more blocks --- diff --git a/android/assets/terrain.png b/android/assets/terrain.png index 4a9c27b..821b3e3 100644 Binary files a/android/assets/terrain.png and b/android/assets/terrain.png differ diff --git a/android/assets/terrain_mc.png b/android/assets/terrain_mc.png index d2e3b85..1638c20 100644 Binary files a/android/assets/terrain_mc.png and b/android/assets/terrain_mc.png differ diff --git a/core/src/ru/deadsoftware/cavecraft/Assets.java b/core/src/ru/deadsoftware/cavecraft/Assets.java index 3764a58..9d06345 100644 --- a/core/src/ru/deadsoftware/cavecraft/Assets.java +++ b/core/src/ru/deadsoftware/cavecraft/Assets.java @@ -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; diff --git a/core/src/ru/deadsoftware/cavecraft/Items.java b/core/src/ru/deadsoftware/cavecraft/Items.java index 2a4071f..2b24741 100644 --- a/core/src/ru/deadsoftware/cavecraft/Items.java +++ b/core/src/ru/deadsoftware/cavecraft/Items.java @@ -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)); } } diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index 3bd467d..2d59d34 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -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) + 10 && 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; diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index cc3bcde..84060ca 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -61,7 +61,8 @@ public class GameRenderer { if (maxY>gameProc.world.getHeight()) maxY = gameProc.world.getHeight(); for (int y=minY; y0) { + 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; y0 && + 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(); diff --git a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java index 5bc94ff..7e676f8 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java +++ b/core/src/ru/deadsoftware/cavecraft/game/WorldGen.java @@ -43,14 +43,17 @@ public class WorldGen { dirtH = 4+rand.nextInt(2); for (int y = height- hMap[x]; y