我正在 MonoGame 中制作一个随机生成的瓷砖游戏,并且我正在尝试使用 Simplex Noise 来生成地形。问题是,我以前从未使用过 Simplex Noise,所以您可能会猜到,我的代码不起作用。它只创建草瓷砖。这是我尝试过的代码:
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;
}
我正在使用这个实现来产生噪音。