MonoGame中的SimplexNoise地形SimplexNoise terrain in MonoGame

``````public void Generate() {
Tiles = new List<Tile>();
Seed = GenerateSeed();
for (int x = 0; x < Width; x++) {
for (int y = 0; y < Height; y++) {
float value = Noise.Generate((x / Width) * Seed, (y / Height) * Seed) / 10.0f;
if (value <= 0.1f) {
Tiles.Add(new Tile(Main.TileGrass, new Vector2((int)x * Tile.Size, (int)y * Tile.Size)));
}
else if (value > 0.1f && value <= 0.5f) {
Tiles.Add(new Tile(Main.TileSand, new Vector2((int)x * Tile.Size, (int)y * Tile.Size)));
}
else {
Tiles.Add(new Tile(Main.TileWater, new Vector2((int)x * Tile.Size, (int)y * Tile.Size)));
}
}
}
}

public int GenerateSeed() {
Random random = new Random();
int length = 8;
int result = 0;

for (int i = 0; i < length; i++) {
result += random.Next(0, 9);
}

return result;
}
``````

1 个回复1

===============>>#1 票数：1 已采纳

``````// The result is scaled to return values in the interval [-1,1].
``````

• 加1（范围从0到2）。
• 除以2（范围为0到1）。

``````float value = (Noise.Generate((x / Width) * Seed, (y / Height) * Seed) + 1) / 2.0f;
``````

``````if (value <= -0.8f)
{
Tiles.Add(new Tile(Main.TileGrass, new Vector2((int)x * Tile.Size, (int)y * Tile.Size)));
}
else if (value <= 0)
{
Tiles.Add(new Tile(Main.TileSand, new Vector2((int)x * Tile.Size, (int)y * Tile.Size)));
}
else
{
Tiles.Add(new Tile(Main.TileWater, new Vector2((int)x * Tile.Size, (int)y * Tile.Size)));
}
``````