diff --git a/core/assets/air.png b/core/assets/air.png new file mode 100644 index 0000000..22d5f8a Binary files /dev/null and b/core/assets/air.png differ diff --git a/core/src/com/mygdx/game/Dimension/Block.java b/core/src/com/mygdx/game/Dimension/Block.java index 4572a82..cdb93b0 100644 --- a/core/src/com/mygdx/game/Dimension/Block.java +++ b/core/src/com/mygdx/game/Dimension/Block.java @@ -6,7 +6,7 @@ public class Block { private Boolean breakable; private Boolean passable; - public Block(String name, Boolean harvestable, Boolean breakable, Boolean passable) { + public Block(String name) { this.name = name; this.harvestable = harvestable; this.breakable = breakable; diff --git a/core/src/com/mygdx/game/Dimension/BlockMaterials.java b/core/src/com/mygdx/game/Dimension/BlockMaterials.java index a593826..97e0953 100644 --- a/core/src/com/mygdx/game/Dimension/BlockMaterials.java +++ b/core/src/com/mygdx/game/Dimension/BlockMaterials.java @@ -16,12 +16,13 @@ public class BlockMaterials { } public static void create(){ - materials.put("grass",new Block("grass",true,false,true)); - materials.put("wood",new Block("wood",false,true,true)); - materials.put("water",new Block("water",true,false,false)); - materials.put("stone",new Block("stone",true,false,false)); - materials.put("snow",new Block("snow",true,false,false)); - materials.put("sand",new Block("sand",true,false,false)); + materials.put("grass",new Block("grass")); + materials.put("wood",new Block("wood")); + materials.put("water",new Block("water")); + materials.put("stone",new Block("stone")); + materials.put("snow",new Block("snow")); + materials.put("sand",new Block("sand")); + materials.put("air",new Block("air")); textures.put("grass", new Texture("core/assets/grass.png")); textures.put("wood", new Texture("core/assets/wood.png")); @@ -29,5 +30,6 @@ public class BlockMaterials { textures.put("stone", new Texture("core/assets/stone.png")); textures.put("snow", new Texture("core/assets/snow.png")); textures.put("sand", new Texture("core/assets/sand.png")); + textures.put("air", new Texture("core/assets/air.png")); } } diff --git a/core/src/com/mygdx/game/Dimension/Chunks.java b/core/src/com/mygdx/game/Dimension/Chunks.java index 84f66fa..beab482 100644 --- a/core/src/com/mygdx/game/Dimension/Chunks.java +++ b/core/src/com/mygdx/game/Dimension/Chunks.java @@ -1,7 +1,7 @@ //https://www.redblobgames.com/maps/terrain-from-noise/ package com.mygdx.game.Dimension; -import com.github.czyzby.kiwi.util.tuple.immutable.Pair; +import com.github.czyzby.kiwi.util.tuple.immutable.Triple; import com.mygdx.game.OpenSimplexNoise; import java.util.HashMap; @@ -9,7 +9,7 @@ import java.util.HashMap; import static com.mygdx.game.Restrictions.*; public class Chunks { - public static HashMap, Block> blocks = new HashMap<>(); + public static HashMap, Block> blocks = new HashMap<>(); private long seed = SEED; public void ungenerateChunk(int x, int y) { @@ -21,7 +21,14 @@ public class Chunks { //Going from start of selected chunk to end of selected chunk in x and y for (int i = startX; i != endX; i++){ for (int j = startY; j != endY; j++) { - blocks.remove(new Pair<>(i, j), getTerrain(i, j)); + blocks.remove(new Triple<>(i, j,0), getTerrain(i, j)); + } + } + //Second Layer + for (int i = startX; i != endX; i++){ + for (int j = startY; j != endY; j++) { + Triple triple = new Triple<>(i, j,1); + blocks.remove(triple, blocks.get(triple)); } } } @@ -35,9 +42,25 @@ public class Chunks { //Going from start of selected chunk to end of selected chunk in x and y for (int i = startX; i != endX; i++){ for (int j = startY; j != endY; j++) { - blocks.put(new Pair<>(i, j), getTerrain(i, j)); + blocks.put(new Triple<>(i, j, 0), getTerrain(i, j)); } } + + //Second Layer + for (int i = startX; i != endX; i++){ + for (int j = startY; j != endY; j++) { + Triple triple = new Triple<>(i, j,1); + blocks.put(triple, getBuildings(i,j)); + } + } + } + + public Block getBuildings(int x, int y) { + if(x == 2 && y == 2) return new Block("wood"); + if(x == 2 && y == 1) return new Block("wood"); + if(x == 1 && y == 2) return new Block("wood"); + if(x == 1 && y == 1) return new Block("wood"); + return new Block("air"); } public double noise1(double nx, double ny) { @@ -52,10 +75,6 @@ public class Chunks { return gen2.eval(nx, ny)/2 + 0.5; } - public Boolean isEmpty(int x, int y){ - return blocks.get(new Pair<>(x * 8, y * 8)) == null; - } - public Block getTerrain(int x, int y) { double moisture, elevation,nx,ny; double scale = 0.01; @@ -133,4 +152,8 @@ public class Chunks { if (moisture < 0.66) return "TropicalSeasonalForest"; return "TropicalRainForest"; } + + public Boolean isEmpty(int x, int y){ + return blocks.get(new Triple<>(x * 8, y * 8,0)) == null; + } } diff --git a/core/src/com/mygdx/game/Dimension/WorldRenderer.java b/core/src/com/mygdx/game/Dimension/WorldRenderer.java index be4bd09..0c50d83 100644 --- a/core/src/com/mygdx/game/Dimension/WorldRenderer.java +++ b/core/src/com/mygdx/game/Dimension/WorldRenderer.java @@ -2,7 +2,7 @@ package com.mygdx.game.Dimension; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.github.czyzby.kiwi.util.tuple.immutable.Pair; +import com.github.czyzby.kiwi.util.tuple.immutable.Triple; import com.mygdx.game.Character.InputController; import com.mygdx.game.Character.Mouse; import com.mygdx.game.Restrictions; @@ -18,19 +18,23 @@ public class WorldRenderer implements Restrictions { inputController = new InputController(); } - public void drawWorld(Batch batch) { - for (Pair chunkpair : Chunks.blocks.keySet()) { - String name = Chunks.blocks.get(chunkpair).getName(); - batch.draw( - BlockMaterials.getTexture(name), - chunkpair.getFirst() << TILE_SHIFT, - chunkpair.getSecond() << TILE_SHIFT - ); + public void drawWorld(Batch batch, int layer) { + for (Triple chunkpair : Chunks.blocks.keySet()) { + String name = null; + if(chunkpair.getThird() == layer) { + name = Chunks.blocks.get(chunkpair).getName(); + batch.draw( + BlockMaterials.getTexture(name), + chunkpair.getFirst() << TILE_SHIFT, + chunkpair.getSecond() << TILE_SHIFT + ); + } } } public void render(SpriteBatch batch) { - drawWorld(batch); + drawWorld(batch,0); + drawWorld(batch,1); inputController.handleInput(); batch.setProjectionMatrix(cam.combined); cam.update(); diff --git a/core/src/com/mygdx/game/Main.java b/core/src/com/mygdx/game/Main.java index c7c96e3..42b0fda 100644 --- a/core/src/com/mygdx/game/Main.java +++ b/core/src/com/mygdx/game/Main.java @@ -21,7 +21,6 @@ public class Main extends ApplicationAdapter { private GUI gui; private FitViewport fitViewport; public static float delta = 0; - float physicsUpdateSpeed = 1/60f; //how often you want to do a physics-update, in this case every 1/60th of a sec float timeSinceLastUpdate = 0f; //accumulator public static OrthographicCamera cam;