private float GetBlockNoise(int blockX, int blockZ)
        {
            float mediumDetail = PerlinSimplexNoise.noise(blockX / 300.0f, blockZ / 300.0f, 20);
            float fineDetail   = PerlinSimplexNoise.noise(blockX / 80.0f, blockZ / 80.0f, 30);
            float bigDetails   = PerlinSimplexNoise.noise(blockX / 800.0f, blockZ / 800.0f);
            float noise        = bigDetails * 64.0f + mediumDetail * 32.0f + fineDetail * 16.0f; // *(bigDetails

            // *
            // 64.0f);
            return(noise + 16);
        }
Ejemplo n.º 2
0
        protected virtual void generateTerrain(Region chunk, int blockXInChunk, int blockZInChunk, int worldX, int worldY, int worldDepthInBlocks)
        {
            // The lower ground level is at least this high.
            int minimumGroundheight = worldDepthInBlocks / 4;
            int minimumGroundDepth  = (int)(worldDepthInBlocks * 0.75f);

            float octave1           = PerlinSimplexNoise.noise(worldX * 0.0001f, worldY * 0.0001f) * 0.5f;
            float octave2           = PerlinSimplexNoise.noise(worldX * 0.0005f, worldY * 0.0005f) * 0.25f;
            float octave3           = PerlinSimplexNoise.noise(worldX * 0.005f, worldY * 0.005f) * 0.12f;
            float octave4           = PerlinSimplexNoise.noise(worldX * 0.01f, worldY * 0.01f) * 0.12f;
            float octave5           = PerlinSimplexNoise.noise(worldX * 0.03f, worldY * 0.03f) * octave4;
            float lowerGroundHeight = octave1 + octave2 + octave3 + octave4 + octave5;

            lowerGroundHeight = lowerGroundHeight * minimumGroundDepth + minimumGroundheight;
            bool      sunlit    = true;
            BlockType blockType = BlockType.None;

            for (int y = worldDepthInBlocks - 1; y >= 0; y--)
            {
                if (y <= lowerGroundHeight)
                {
                    if (sunlit)
                    {
                        blockType = BlockType.Grass;
                        sunlit    = false;
                    }
                    else
                    {
                        blockType = BlockType.Rock;
                    }
                }

                chunk.AddBlock(blockXInChunk, y, blockZInChunk, blockType);
                // Debug.WriteLine(string.Format("chunk {0} : ({1},{2},{3})={4}", chunk.Position, blockXInChunk, y, blockZInChunk, blockType));
            }
        }
        protected override void generateTerrain(Region chunk, int x, int z, int blockX, int blockZ, int worldDepthInBlocks)
        {
            int groundHeight = (int)GetBlockNoise(blockX, blockZ);

            if (groundHeight < 1)
            {
                groundHeight = 1;
            }
            else if (groundHeight > 128)
            {
                groundHeight = 96;
            }

            // Default to sunlit.. for caves
            bool      sunlit    = true;
            BlockType BlockType = BlockType.None;

            chunk.Blocks[x, groundHeight, z] = BlockType.Grass;
            chunk.Blocks[x, 0, z]            = BlockType.Dirt;
            for (int y = worldDepthInBlocks - 1; y > 0; y--)
            {
                if (y > groundHeight)
                {
                    BlockType = BlockType.None;
                }

                // Or we at or below ground height?
                else if (y < groundHeight)
                {
                    // Since we are at or below ground height, let's see if we need
                    // to make
                    // a cave
                    int   noiseX  = (blockX + WorldSettings.SEED);
                    float octave1 = PerlinSimplexNoise.noise(noiseX * 0.009f, blockZ * 0.009f, y * 0.009f) * 0.25f;

                    float initialNoise = octave1 + PerlinSimplexNoise.noise(noiseX * 0.04f, blockZ * 0.04f, y * 0.04f) * 0.15f;
                    initialNoise += PerlinSimplexNoise.noise(noiseX * 0.08f, blockZ * 0.08f, y * 0.08f) * 0.05f;

                    if (initialNoise > 0.2f)
                    {
                        BlockType = BlockType.None;
                    }
                    else
                    {
                        // We've placed a block of dirt instead...nothing below us
                        // will be sunlit
                        if (sunlit)
                        {
                            sunlit    = false;
                            BlockType = BlockType.Grass;
                            //chunk.addGrassBlock(x,y,z);
                        }
                        else
                        {
                            BlockType = BlockType.Dirt;
                            if (octave1 < 0.2f)
                            {
                                BlockType = BlockType.Rock;
                            }
                        }
                    }
                }

                chunk.AddBlock(x, y, z, BlockType);
            }
        }