Exemple #1
0
        private static IHeightMap GenerateRocks(int seed, int x, int y, double density)
        {
            CellularAutomaton ca = new CellularAutomaton(seed, new RuleSet(Lerp(0.1, 0.3, density), false, (region, generation) => region.GetNeighbors() > 2));

            IHeightMap layer1 = new BooleanMap(ca.Generate(x, y, 4));
            IHeightMap layer2 = new BooleanMap(ca.Generate(x, y, 2));

            return(new HeightMap(2, ValueArray.Create(x, y, (i, j) => layer1[i, j] + layer2[i, j])));
        }
Exemple #2
0
        public Cave(int seed, int x, int y, double wallDensity, double rockDensity)
        {
            Random random = new Random(seed);

            bool[,] bounds = GenerateBounds(random.Next(), x, y, 5, -1);
            bool[,] walls  = GenerateWalls(random.Next(), x, y, wallDensity);
            bool[,] map    = ValueArray.Create(x, y, (i, j) => bounds[i, j] || walls[i, j]);
            MainArea       = FillHoles(map);
            IHeightMap rocks = GenerateRocks(random.Next(), x, y, rockDensity);

            SizeX     = x;
            SizeY     = y;
            MaxHeight = rocks.MaxHeight + 1;

            this.map = new HeightMap(MaxHeight, ValueArray.Create(x, y, (i, j) => map[i, j] ? MaxHeight : rocks[i, j]));
        }