当前位置: 首页>>代码示例>>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;未经允许,请勿转载。