使用OpenSimplex噪音:https://gist.github.com/KdotJPG/b1270127455a94ac5d19
不要sommething像:
protected void generateLevel() {
OpenSimplexNoise noise = new OpenSimplexNoise(); //optionally pass in a seed.
for (int y = 0 y < height; y++) {
for (int x = 0; x < width; x++) {
double value = noise.eval(x/24.0, y/24.0, 0.5);
if (value < 0) {
tiles[x + y * width] = 6; //set water
} else {
tiles[x + y * width] = 1; //set grass
}
}
}
}
也有替代品,如柏林噪聲和單純的噪音。我會完全忽略柏林噪聲,因爲它往往會呈現視覺上重要的網格僞像(它將其所有特徵與其底層方形網格對齊)。 2D中的單純形噪聲是可以的,儘管互聯網上2D Simplex噪聲的大部分實現都使用奇怪的梯度集,導致僞像沿負對角線下降。而3D單工噪音則受到專利保護。
Perlin雜VS OpenSimplex噪聲,3D的2D切片:
- 左是噪聲(X,Y,0)灰度
- 接下來是噪聲(X,Y,0)> 0?白色:黑色
- 接下來是| noise(x,y,0)| > 0.1?白:黑
- 接下來是噪聲(X,Y,0.5)灰度
編輯:下面是從註釋的代碼
分形噪聲:
OpenSimplexNoise n1 = new OpenSimplexNoise(seed1);
OpenSimplexNoise n2 = new OpenSimplexNoise(seed2);
OpenSimplexNoise n3 = new OpenSimplexNoise(seed3);
for each x,y {
double value = (n1.eval(x/48.0, y/48.0, 0.5) + n2.eval(x/24.0, y/24.0, 0.5) * .5 + n3.eval(x/12.0, y/12.0, 0.5) * .25)/(1 + .5 + .25);
//Do whatever you need to with that value
}
河流:
if (value > -0.1 || value < 0.1)
water
else
land
生物羣系:
OpenSimplexNoise n1 = new OpenSimplexNoise(seed1);
OpenSimplexNoise n2 = new OpenSimplexNoise(seed2);
OpenSimplexNoise n3 = new OpenSimplexNoise(seed3);
for each x,y {
double elevation = n1.eval(x/24.0, y/24.0, 0.5);
double temperature = n2.eval(x/24.0, y/24.0, 0.5);
double precipitation = n3.eval(x/24.0, y/24.0, 0.5);
if (elevation < 0)
water
else {
//decide biome based on temperature, precipitation, and elevation
}
}
您能否定義逼真的效果?你的地形應該成爲一個擁有一些河流的島嶼嗎?您可以定義河流或湖泊片段並將其隨機放置在您的地形上 – Mosa 2014-10-27 22:35:40