Exemple #1
0
        /// <summary>
        /// Create a relatively flat ground.
        /// </summary>
        /// <param name="rand"></param>
        private void GeneratePlainLevel(ref Random rand, float heightOffset = 0.2f)
        {
            ValueNoise noise = new ValueNoise(ref rand, 3, 8);
            // Fill half to test
            Int32 maxHeight = Math.Min(8, SizeY - 1);

            Parallel.For(0, SizeZ, (z) => {
                for (int x = 0; x < SizeX; ++x)
                {
                    float radialHeight = 0.02f * (float)Math.Sqrt((x - SizeX / 2) * (x - SizeX / 2) + (z - SizeZ / 2) * (z - SizeZ / 2));
                    int height         = (int)(maxHeight * (noise.Get(x, z) - radialHeight + heightOffset));
                    for (int y = 0; y < height; ++y)
                    {
                        Set(EncodePosition(x, y, z), VoxelType.GROUND, false);
                    }
                }
            });
        }
Exemple #2
0
        private void GenerateCanoynsLevel(ref Random rand, float heightOffset)
        {
            ValueNoise noise       = new ValueNoise(ref rand, 3, 8);
            int        sizeYscaled = SizeY / 3;

            // Fill half to test
            Parallel.For(0, SizeZ, (z) => {
                for (int x = 0; x < SizeX; ++x)
                {
                    Set(EncodePosition(x, 0, z), VoxelType.ROCK, false);
                    for (int d = 1; d < sizeYscaled; ++d)
                    {
                        float value = noise.Get(x / 2, z / 2, d / 5) - 0.5f;
                        if (value > 0)
                        {
                            Set(EncodePosition(x, d, z), VoxelType.ROCK, false);
                        }
                    }
                    for (int d = sizeYscaled; d < sizeYscaled + 5; ++d)
                    {
                        float value = noise.Get(x / 2, z / 2, d / 5) - 0.6f;
                        if (value > 0)
                        {
                            Set(EncodePosition(x, d, z), VoxelType.ROCK, false);
                        }
                    }
                    // Ground on top
                    for (int d = SizeY - 1; d >= 0; --d)
                    {
                        Int32 pos = EncodePosition(x, d, z);
                        if (_voxels[pos] != 0)
                        {
                            Set(pos, VoxelType.GROUND, false);
                            break;
                        }
                    }
                }
            });
        }
Exemple #3
0
        private void GenerateMountainsLevel(ref Random rand, float heightOffset)
        {
            ValueNoise noise       = new ValueNoise(ref rand, 3, 8);
            int        sizeYscaled = SizeY / 3;

            // Fill half to test
            Parallel.For(0, SizeZ, (z) => {
                for (int x = 0; x < SizeX; ++x)
                {
                    for (int d = 0; d < SizeY; ++d)
                    {
                        float radialHeight = Math.Max(0.0f, (float)Math.Sqrt((x - SizeX / 2) * (x - SizeX / 2) + (z - SizeZ / 2) * (z - SizeZ / 2)) - SizeX * 3 / 8) * 2.0f;
                        float value        = (noise.Get(x, z, d) * 3 - heightOffset + noise.Get(x / 2, z / 2)) * sizeYscaled - d;
                        value -= radialHeight;
                        if (value > 0)
                        {
                            Set(EncodePosition(x, d, z), VoxelType.GROUND, false);
                        }
                    }
                }
            });

            Rockyfy();
        }
Exemple #4
0
        private void GenerateBubbleLevel(ref Random rand, float heightOffset)
        {
            ValueNoise noise       = new ValueNoise(ref rand, 3, 8);
            int        sizeYscaled = SizeY / 3;

            // Fill half to test
            Parallel.For(0, SizeZ, (z) => {
                for (int x = 0; x < SizeX; ++x)
                {
                    for (int d = 0; d < SizeY; ++d)
                    {
                        float radialHeight = 8.0f / SizeX * (float)Math.Sqrt((x - SizeX / 2) * (x - SizeX / 2) + (z - SizeZ / 2) * (z - SizeZ / 2));
                        float value        = SizeY * (noise.Get(x, z, d) - noise.Get(x, z)) / radialHeight - heightOffset - radialHeight - Math.Max(0, d - sizeYscaled) * 2;
                        // for (int y = 0; y < height; ++y)
                        if (value > 0)
                        {
                            Set(EncodePosition(x, d, z), VoxelType.GROUND, false);
                        }
                    }
                }
            });

            Rockyfy();
        }
Exemple #5
0
 /// <summary>
 /// Create a relatively flat ground.
 /// </summary>
 /// <param name="rand"></param>
 private void GeneratePlainLevel(ref Random rand, float heightOffset = 0.2f)
 {
     ValueNoise noise = new ValueNoise(ref rand, 3, 8);
     // Fill half to test
     Int32 maxHeight = Math.Min( 8, SizeY-1 );
     Parallel.For( 0, SizeZ, (z) => {
         for (int x = 0; x < SizeX; ++x)
         {
             float radialHeight = 0.02f * (float)Math.Sqrt((x - SizeX / 2) * (x - SizeX / 2) + (z - SizeZ / 2) * (z - SizeZ / 2));
             int height = (int)(maxHeight * (noise.Get(x, z) - radialHeight + heightOffset));
             for (int y = 0; y < height; ++y)
                 Set(EncodePosition(x, y, z), VoxelType.GROUND, false);
         }
     });
 }
Exemple #6
0
        private void GenerateMountainsLevel(ref Random rand, float heightOffset)
        {
            ValueNoise noise = new ValueNoise(ref rand, 3, 8);
            int sizeYscaled = SizeY / 3;
            // Fill half to test
            Parallel.For( 0, SizeZ, (z) => {
                for (int x = 0; x < SizeX; ++x)
                    for (int d = 0; d < SizeY; ++d)
                    {
                        float radialHeight = Math.Max(0.0f, (float)Math.Sqrt((x - SizeX / 2) * (x - SizeX / 2) + (z - SizeZ / 2) * (z - SizeZ / 2)) - SizeX * 3 / 8) * 2.0f;
                        float value = (noise.Get(x, z, d) * 3 - heightOffset + noise.Get(x / 2, z / 2)) * sizeYscaled - d;
                        value -= radialHeight;
                        if (value > 0)
                            Set(EncodePosition(x, d, z), VoxelType.GROUND, false);
                    }
            });

            Rockyfy();
        }
Exemple #7
0
 private void GenerateCanoynsLevel(ref Random rand, float heightOffset)
 {
     ValueNoise noise = new ValueNoise(ref rand, 3, 8);
     int sizeYscaled = SizeY / 3;
     // Fill half to test
     Parallel.For( 0, SizeZ, (z) => {
         for (int x = 0; x < SizeX; ++x)
         {
             Set(EncodePosition(x, 0, z), VoxelType.ROCK, false);
             for (int d = 1; d < sizeYscaled; ++d)
             {
                 float value = noise.Get(x / 2, z / 2, d / 5) - 0.5f;
                 if (value > 0)
                     Set(EncodePosition(x, d, z), VoxelType.ROCK, false);
             }
             for (int d = sizeYscaled; d < sizeYscaled+5; ++d)
             {
                 float value = noise.Get(x / 2, z / 2, d / 5) - 0.6f;
                 if (value > 0)
                     Set(EncodePosition(x, d, z), VoxelType.ROCK, false);
             }
             // Ground on top
             for (int d = SizeY-1; d >= 0; --d)
             {
                 Int32 pos = EncodePosition(x, d, z);
                 if( _voxels[pos] != 0 )
                 {
                     Set(pos, VoxelType.GROUND, false);
                     break;
                 }
             }
         }
     });
 }
Exemple #8
0
        private void GenerateBubbleLevel(ref Random rand, float heightOffset)
        {
            ValueNoise noise = new ValueNoise(ref rand, 3, 8);
            int sizeYscaled = SizeY / 3;
            // Fill half to test
            Parallel.For( 0, SizeZ, (z) => {
                for (int x = 0; x < SizeX; ++x)
                    for (int d = 0; d < SizeY; ++d)
                    {
                        float radialHeight = 8.0f / SizeX * (float)Math.Sqrt((x - SizeX / 2) * (x - SizeX / 2) + (z - SizeZ / 2) * (z - SizeZ / 2));
                        float value = SizeY * (noise.Get(x, z, d) - noise.Get(x, z)) / radialHeight - heightOffset - radialHeight - Math.Max(0, d - sizeYscaled)*2;
                        // for (int y = 0; y < height; ++y)
                        if (value > 0)
                            Set(EncodePosition(x, d, z), VoxelType.GROUND, false);
                    }
            });

            Rockyfy();
        }