Exemplo n.º 1
0
        public void build(Region chunk)
        {
            int sizeY = WorldSettings.REGIONHEIGHT;
            int sizeX = WorldSettings.REGIONWIDTH;
            int sizeZ = WorldSettings.REGIONLENGTH;

            for (int y = 0; y < sizeY; y++)
            {
                for (int x = 0; x < sizeX; x++)
                {
                    for (int z = 0; z < sizeZ; z++)
                    {
                        BlockType t;

                        if (y < sizeY / 4)
                        {
                            t = BlockType.Lava;
                        }

                        /*
                         * else if (y == (sizeY / 2) - 1) // test caves visibility t
                         * = Type.empty;
                         */
                        else if (y < sizeY / 2)
                        {
                            t = BlockType.Rock;
                        }
                        else if (y == sizeY / 2)
                        {
                            t = BlockType.Grass;
                        }
                        else
                        {
                            if (y == sizeY / 2 + 1 && (x == 0 || x == sizeX - 1 || z == 0 || z == sizeZ - 1))
                            {
                                t = BlockType.Brick;
                            }
                            else
                            {
                                t = BlockType.None;
                            }
                        }


                        chunk.AddBlock(x, y, z, t);
                    }
                }
            }
        }
Exemplo 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));
            }
        }
Exemplo n.º 3
0
        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 = BlockType.Grass;
            chunk.Blocks[x, 0, z].BlockType            = 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);
            }
        }