Added biomes based off of moisture and elevation just elevation
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
//https://www.redblobgames.com/maps/terrain-from-noise/
|
||||||
package com.mygdx.game.Dimension;
|
package com.mygdx.game.Dimension;
|
||||||
|
|
||||||
import com.mygdx.game.OpenSimplexNoise;
|
import com.mygdx.game.OpenSimplexNoise;
|
||||||
@@ -9,7 +10,8 @@ import static com.mygdx.game.Restrictions.CHUNK_SIZE;
|
|||||||
|
|
||||||
public class Chunks {
|
public class Chunks {
|
||||||
public HashMap<Pair<Integer, Integer>, Block> blocks = new HashMap<>();
|
public HashMap<Pair<Integer, Integer>, Block> blocks = new HashMap<>();
|
||||||
private long seed = 10000;
|
private long seed = 1;
|
||||||
|
|
||||||
|
|
||||||
public void generateChunk(int x, int y){
|
public void generateChunk(int x, int y){
|
||||||
int startX = x*CHUNK_SIZE;
|
int startX = x*CHUNK_SIZE;
|
||||||
@@ -25,27 +27,91 @@ public class Chunks {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Block getTerrain(int i, int j) {
|
public double noise1(double nx, double ny) {
|
||||||
OpenSimplexNoise openSimplexNoise = new OpenSimplexNoise(seed);
|
OpenSimplexNoise gen1 = new OpenSimplexNoise(seed);
|
||||||
double terrainType = openSimplexNoise.eval(i*0.001,j*0.001);
|
|
||||||
|
|
||||||
if(terrainType < 0){
|
return gen1.eval(nx, ny)/2 + 0.5;
|
||||||
return BlockMaterials.materials.get("water");
|
|
||||||
}
|
|
||||||
else if(terrainType < 0.05 && terrainType > 0){
|
|
||||||
return BlockMaterials.materials.get("sand");
|
|
||||||
}
|
|
||||||
else if (terrainType > 0.7){
|
|
||||||
return BlockMaterials.materials.get("snow");
|
|
||||||
}
|
|
||||||
else if (terrainType > 0.5){
|
|
||||||
return BlockMaterials.materials.get("stone");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return BlockMaterials.materials.get("grass");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double noise2(double nx, double ny) {
|
||||||
|
OpenSimplexNoise gen2 = new OpenSimplexNoise(seed);
|
||||||
|
|
||||||
|
return gen2.eval(nx, ny)/2 + 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block getTerrain(int x, int y) {
|
||||||
|
double moisture, elevation,nx,ny = 0.0;
|
||||||
|
double scale = 0.01;
|
||||||
|
nx = x * scale;
|
||||||
|
ny = y * scale;
|
||||||
|
elevation = (0.17 * noise1( 1 * nx, 1 * ny)
|
||||||
|
+ 0.42 * noise1( 2 * nx, 2 * ny)
|
||||||
|
+ 0.16 * noise1( 4 * nx, 4 * ny)
|
||||||
|
+ 0.00 * noise1( 8 * nx, 8 * ny)
|
||||||
|
+ 0.00 * noise1(16 * nx, 16 * ny)
|
||||||
|
+ 0.03 * noise1(32 * nx, 32 * ny));
|
||||||
|
elevation /= (0.17+0.42+0.16+0.00+0.00+0.03);
|
||||||
|
elevation = Math.pow(elevation, 3.00);
|
||||||
|
moisture = (1.00 * noise2( 1 * nx, 1 * ny)
|
||||||
|
+ 0.75 * noise2( 2 * nx, 2 * ny)
|
||||||
|
+ 0.33 * noise2( 4 * nx, 4 * ny)
|
||||||
|
+ 0.33 * noise2( 8 * nx, 8 * ny)
|
||||||
|
+ 0.33 * noise2(16 * nx, 16 * ny)
|
||||||
|
+ 0.50 * noise2(32 * nx, 32 * ny));
|
||||||
|
moisture /= (1.00+0.75+0.33+0.33+0.33+0.50);
|
||||||
|
|
||||||
|
return getBiomeBlock(moisture, elevation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block getBiomeBlock(double moisture, double elevation) {
|
||||||
|
String biome = getBiome(moisture,elevation);
|
||||||
|
if (biome.equals("Tundra")) return BlockMaterials.materials.get("snow");
|
||||||
|
if (biome.equals("Taiga")) return BlockMaterials.materials.get("snow");
|
||||||
|
if (biome.equals("Snow")) return BlockMaterials.materials.get("snow");
|
||||||
|
if (biome.equals("Grassland")) return BlockMaterials.materials.get("grass");
|
||||||
|
if (biome.equals("Shrubland")) return BlockMaterials.materials.get("grass");
|
||||||
|
if (biome.equals("TemperateDeciduousForest")) return BlockMaterials.materials.get("grass");
|
||||||
|
if (biome.equals("TemperateRainForest")) return BlockMaterials.materials.get("grass");
|
||||||
|
if (biome.equals("TropicalSeasonalForest")) return BlockMaterials.materials.get("grass");
|
||||||
|
if (biome.equals("TropicalForest")) return BlockMaterials.materials.get("grass");
|
||||||
|
if (biome.equals("Beach")) return BlockMaterials.materials.get("sand");
|
||||||
|
if (biome.equals("Bare")) return BlockMaterials.materials.get("sand");
|
||||||
|
if (biome.equals("Scorched")) return BlockMaterials.materials.get("sand");
|
||||||
|
if (biome.equals("TemperateDesert")) return BlockMaterials.materials.get("sand");
|
||||||
|
if (biome.equals("SubtropicalDesert")) return BlockMaterials.materials.get("sand");
|
||||||
|
else return BlockMaterials.materials.get("water");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getBiome(double moisture,double elevation){
|
||||||
|
if (elevation < 0.1) return "Ocean";
|
||||||
|
if (elevation < 0.12) return "Beach";
|
||||||
|
|
||||||
|
if (elevation > 0.8) {
|
||||||
|
if (moisture < 0.1) return "Scorched";
|
||||||
|
if (moisture < 0.2) return "Bare";
|
||||||
|
if (moisture < 0.5) return "Tundra";
|
||||||
|
return "Snow";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elevation > 0.6) {
|
||||||
|
if (moisture < 0.33) return "TemperateDesert";
|
||||||
|
if (moisture < 0.66) return "Shrubland";
|
||||||
|
return "Taiga";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elevation > 0.3) {
|
||||||
|
if (moisture < 0.16) return "TemperateDesert";
|
||||||
|
if (moisture < 0.50) return "Grassland";
|
||||||
|
if (moisture < 0.83) return "TemperateDeciduousForest";
|
||||||
|
return "TemperateRainForest";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (moisture < 0.16) return "SubtropicalDesert";
|
||||||
|
if (moisture < 0.33) return "Grassland";
|
||||||
|
if (moisture < 0.66) return "TropicalSeasonalForest";
|
||||||
|
return "TropicalRainForest";
|
||||||
|
}
|
||||||
|
|
||||||
public HashMap<Pair<Integer, Integer>, Block> getBlocks() {
|
public HashMap<Pair<Integer, Integer>, Block> getBlocks() {
|
||||||
return blocks;
|
return blocks;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ public interface Restrictions {
|
|||||||
float VIEWPORT_HEIGHT = 9/2f;
|
float VIEWPORT_HEIGHT = 9/2f;
|
||||||
float VIEWPORT_WIDTH = 16/2f;
|
float VIEWPORT_WIDTH = 16/2f;
|
||||||
int MOVEMENT_SPEED = 16;
|
int MOVEMENT_SPEED = 16;
|
||||||
int KEY_DELAY = 4;
|
int KEY_DELAY = 0;
|
||||||
int CHUNK_SIZE = 16;
|
int CHUNK_SIZE = 16;
|
||||||
int SUPER_CHUNK_SIZE = 3;
|
int SUPER_CHUNK_SIZE = 3;
|
||||||
int RENDER_DISTANCE = 2;
|
int RENDER_DISTANCE = 2;
|
||||||
|
|||||||
Reference in New Issue
Block a user