Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save reidscarboro/d2de441aab41ec360a909c49c7136214 to your computer and use it in GitHub Desktop.
Save reidscarboro/d2de441aab41ec360a909c49c7136214 to your computer and use it in GitHub Desktop.
LibNoise example
int[,] level = new int[200,100]
caveNoiseScalar = 9;
levelRatio = (float) level.GetLength(0) / level.GetLength(1);
RidgedMultifractal mountainTerrain = new RidgedMultifractal();
Noise2D heightMapBuilder = new Noise2D(level.GetLength(0), level.GetLength(1), mountainTerrain);
Vector2Int startPoint = new Vector2Int(Random.Range(0, 8192), Random.Range(0, 8192));
heightMapBuilder.GeneratePlanar(startPoint.x + 0, startPoint.x + caveNoiseScalar * levelRatio, startPoint.y + 0, startPoint.y + caveNoiseScalar);
float[,] heightMap = heightMapBuilder.GetNormalizedData();
for (int x = 0; x < level.GetLength(0); x++) {
for (int y = 0; y < level.GetLength(1); y++) {
float noiseSample = heightMap[x, y];
if (noiseSample > 0.5f) {
//setup the array
level[x, y] = 1;
//or directly instantiate tiles from here
Instantiate(tilePrefab, new Vector3(x, y, 0), Quaternion.identity);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment