Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Generate2()
- {
- Random rnd = new Random();
- Queue<Vector2> heightChanges = new Queue<Vector2>();
- Queue<Vector2> lastHeightChanges = new Queue<Vector2>();
- int initialHeight = rnd.Next(1) + 2;
- for (int y = 0; y < initialHeight; y++)
- {
- cubes[0, y, 0] = new BlockGround(new Vector3(0, 10 * y, 0));
- }
- for (int z = 1; z < _depth; z++)
- {
- int currentHeight = GetHeight(0, z - 1);
- if (rnd.Next(4) == 0)
- {
- int heightDiff = rnd.Next(-1, 1);
- if (heightDiff == 0)
- {
- heightDiff++;
- }
- if (rnd.Next(100) == 0)
- {
- heightDiff *= 2;
- }
- heightChanges.Enqueue(new Vector2(z, heightDiff));
- currentHeight += heightDiff;
- currentHeight = Math.Min(_height, Math.Max(1, currentHeight));
- }
- for (int y = 0; y < currentHeight; y++)
- {
- cubes[0, y, z] = new BlockGround(new Vector3(0, 10 * y, 10 * z));
- }
- }
- for (int x = 1; x < _width; x++)
- {
- int zeroHeight = GetHeight(x, 0);
- lastHeightChanges = heightChanges;
- heightChanges = new Queue<Vector2>();
- for (int z = 0; z < _depth; z++)
- {
- int currentHeight;
- if (z == 0)
- {
- currentHeight = GetHeight(x - 1, z);
- }
- else
- {
- currentHeight = GetHeight(x, z - 1);
- }
- if (lastHeightChanges.Count > 0 && lastHeightChanges.Peek().X == z)
- {
- currentHeight += (int)lastHeightChanges.Peek().Y;
- lastHeightChanges.Dequeue();
- }
- if (rnd.Next(4) == 0)
- {
- int heightDiff = rnd.Next(-1, 1);
- if (heightDiff == 0)
- {
- heightDiff++;
- }
- if (rnd.Next(100) == 0)
- {
- heightDiff *= 2;
- }
- heightChanges.Enqueue(new Vector2(z, heightDiff));
- }
- currentHeight = Math.Min(_height, Math.Max(1, currentHeight));
- currentHeight = Math.Min(zeroHeight + 3, Math.Max(zeroHeight - 3, currentHeight));
- for (int y = 0; y < currentHeight; y++)
- {
- if(y < currentHeight - 1)
- cubes[x, y, z] = new BlockGround(new Vector3(10 * x, 10 * y, 10 * z));
- else
- cubes[x, y, z] = new BlockGrass(new Vector3(10 * x, 10 * y, 10 * z));
- }
- }
- }
- AddAllCubes();
- }
Advertisement
Add Comment
Please, Sign In to add comment