當前位置: 首頁>>代碼示例>>C#>>正文


C# Chunk.SetBlockType方法代碼示例

本文整理匯總了C#中Chunk.SetBlockType方法的典型用法代碼示例。如果您正苦於以下問題:C# Chunk.SetBlockType方法的具體用法?C# Chunk.SetBlockType怎麽用?C# Chunk.SetBlockType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Chunk的用法示例。


在下文中一共展示了Chunk.SetBlockType方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetLowerGroundHeight

    private static float GetLowerGroundHeight(Chunk chunk, int blockWorldX, int blockWorldY, int blockXInChunk,
        int blockYInChunk, int worldDepthInBlocks)
    {
        int minimumGroundheight = worldDepthInBlocks / 4;
        int minimumGroundDepth = (int) (worldDepthInBlocks * 0.5f);

        float octave1 = PerlinSimplexNoise.noise(blockWorldX * 0.0001f, blockWorldY * 0.0001f) * 0.5f;
        float octave2 = PerlinSimplexNoise.noise(blockWorldX * 0.0005f, blockWorldY * 0.0005f) * 0.35f;
        float octave3 = PerlinSimplexNoise.noise(blockWorldX * 0.02f, blockWorldY * 0.02f) * 0.15f;
        float lowerGroundHeight = octave1 + octave2 + octave3;
        lowerGroundHeight = lowerGroundHeight * minimumGroundDepth + minimumGroundheight;

        for (int z = (int) lowerGroundHeight; z >= 0; z--)
        {
            chunk.SetBlockType(blockXInChunk, blockYInChunk, z, BlockType.Dirt);
        }

        return lowerGroundHeight;
    }
開發者ID:scorpion44,項目名稱:BlockPackage,代碼行數:19,代碼來源:DualLayerTerrainWithMediumValleys.cs

示例2: GenerateTerrain

    public void GenerateTerrain(WorldData worldData, Chunk chunk)
    {
        int chunkBlockX = chunk.ArrayX * worldData.ChunkBlockWidth;
        int chunkBlockY = chunk.ArrayY * worldData.ChunkBlockHeight;

        for (int x = 0; x < worldData.ChunkBlockWidth; x++)
        {
            int globalBlockX = chunkBlockX + x + worldData.MapBlockOffset.X;

            for (int y = 0; y < worldData.ChunkBlockHeight; y++)
            {
                int globalBlockY = chunkBlockY + y + worldData.MapBlockOffset.Y;

                float lowerGroundHeight = GetLowerGroundHeight(chunk, globalBlockX, globalBlockY, x, y,
                                                               worldData.DepthInBlocks);
                int groundHeight = GetUpperGroundHeight(worldData, globalBlockX, globalBlockY, lowerGroundHeight);

                bool sunlit = true;
                for (int z = worldData.DepthInBlocks - 1; z >= 0; z--)
                {
                    // Everything above ground height...is air.
                    BlockType blockType;
                    if (z > groundHeight)
                    {
                        blockType = BlockType.Air;
                    }
                        // Are we above the lower ground height?
                    else if (z > lowerGroundHeight)
                    {
                        // Let's see about some caves er valleys!
                        float octave1 =
                            PerlinSimplexNoise.noise(globalBlockX * 0.01f, globalBlockY * 0.01f, z * 0.01f) *
                            (0.015f * z) + 0.1f;
                        float caveNoise = octave1 +
                                          PerlinSimplexNoise.noise(globalBlockX * 0.01f, globalBlockY * 0.01f, z * 0.1f) *
                                          0.06f +
                                          0.1f;
                        caveNoise += PerlinSimplexNoise.noise(globalBlockX * 0.2f, globalBlockY * 0.2f, z * 0.2f) *
                                     0.03f +
                                     0.01f;
                        // We have a cave, draw air here.
                        if (caveNoise > 0.2f)
                        {
                            blockType = BlockType.Air;
                        }
                        else
                        {
                            if (sunlit)
                            {
                                blockType = BlockType.TopSoil;
                                // Remember, this adds the block global coordinates
                                chunk.TopSoilBlocks.Add(new Vector3i(globalBlockX, globalBlockY, z));
                                sunlit = false;
                            }
                            else
                            {
                                blockType = BlockType.Dirt;
                                if (caveNoise < 0.2f)
                                {
                                    blockType = BlockType.Stone;
                                }
                            }
                        }
                    }
                    else
                    {
                        // We are at the lower ground level
                        if (sunlit)
                        {
                            blockType = BlockType.TopSoil;
                            chunk.TopSoilBlocks.Add(new Vector3i(globalBlockX, globalBlockY, z));
                            sunlit = false;
                        }
                        else
                        {
                            blockType = BlockType.Dirt;
                        }
                    }

                    chunk.SetBlockType(x, y, z,blockType);
                }
            }
        }
    }
開發者ID:scorpion44,項目名稱:BlockPackage,代碼行數:84,代碼來源:DualLayerTerrainWithMediumValleys.cs


注:本文中的Chunk.SetBlockType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。