Added multiple layers to the world and was able to make them render
This commit is contained in:
BIN
core/assets/air.png
Normal file
BIN
core/assets/air.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
@@ -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;
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Pair<Integer, Integer>, Block> blocks = new HashMap<>();
|
||||
public static HashMap<Triple<Integer, Integer,Integer>, 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<Integer,Integer,Integer> 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<Integer,Integer,Integer> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Integer, Integer> 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<Integer, Integer, Integer> 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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user