当前位置: 首页>>代码示例>>C#>>正文


C# Map.SetBlock方法代码示例

本文整理汇总了C#中Map.SetBlock方法的典型用法代码示例。如果您正苦于以下问题:C# Map.SetBlock方法的具体用法?C# Map.SetBlock怎么用?C# Map.SetBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Map的用法示例。


在下文中一共展示了Map.SetBlock方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MakeFloodBarrier

        /// <summary> Makes an admincrete barrier, 1 block thick, around the lower half of the map. </summary>
        public static void MakeFloodBarrier( Map map ) {
            for( int x = 0; x < map.Width; x++ ) {
                for( int y = 0; y < map.Length; y++ ) {
                    map.SetBlock( x, y, 0, Block.Admincrete );
                }
            }

            for( int x = 0; x < map.Width; x++ ) {
                for( int z = 0; z < map.Height / 2; z++ ) {
                    map.SetBlock( x, 0, z, Block.Admincrete );
                    map.SetBlock( x, map.Length - 1, z, Block.Admincrete );
                }
            }

            for( int y = 0; y < map.Length; y++ ) {
                for( int z = 0; z < map.Height / 2; z++ ) {
                    map.SetBlock( 0, y, z, Block.Admincrete );
                    map.SetBlock( map.Width - 1, y, z, Block.Admincrete );
                }
            }
        }
开发者ID:fragmer,项目名称:fCraft,代码行数:22,代码来源:RealisticMapGenState.cs

示例2: GenerateMap

        Map GenerateMap() {
            Map map = new Map( null, genParams.MapWidth, genParams.MapLength, genParams.MapHeight, true );
            theme = genParams.Theme;

            // scale features vertically based on map height
            double verticalScale = (genParams.MapHeight / 96.0) / 2 + 0.5;
            maxHeightScaled = (int)Math.Round( genParams.MaxHeight * verticalScale );
            maxDepthScaled = (int)Math.Round( genParams.MaxDepth * verticalScale );
            snowAltitudeScaled = (int)Math.Round( genParams.SnowAltitude * verticalScale );

            // Match water coverage
            float desiredWaterLevel = .5f;
            if( genParams.MatchWaterCoverage ) {
                ReportRelativeProgress( 2, "Heightmap Processing: Matching water coverage" );
                // find a number between 0 and 1 ("desiredWaterLevel") for the heightmap such that
                // the fraction of heightmap coordinates ("blocks") that are below this threshold ("underwater")
                // match the specified WaterCoverage
                desiredWaterLevel = Noise.FindThreshold( heightmap, genParams.WaterCoverage );
            }


            // Calculate above/below water multipliers
            float aboveWaterMultiplier = 0;
            if( desiredWaterLevel < 1 ) {
                aboveWaterMultiplier = (maxHeightScaled / (1 - desiredWaterLevel));
            }


            // Apply power functions to above/below water parts of the heightmap
            if( Math.Abs( genParams.BelowFuncExponent - 1 ) > float.Epsilon ||
                Math.Abs( genParams.AboveFuncExponent - 1 ) > float.Epsilon ) {
                ReportRelativeProgress( 5, "Heightmap Processing: Adjusting slope" );
                for( int x = heightmap.GetLength( 0 ) - 1; x >= 0; x-- ) {
                    for( int y = heightmap.GetLength( 1 ) - 1; y >= 0; y-- ) {
                        if( heightmap[x, y] < desiredWaterLevel ) {
                            float normalizedDepth = 1 - heightmap[x, y]/desiredWaterLevel;
                            heightmap[x, y] = desiredWaterLevel -
                                              (float)Math.Pow( normalizedDepth, genParams.BelowFuncExponent )*
                                              desiredWaterLevel;
                        } else {
                            float normalizedHeight = (heightmap[x, y] - desiredWaterLevel)/(1 - desiredWaterLevel);
                            heightmap[x, y] = desiredWaterLevel +
                                              (float)Math.Pow( normalizedHeight, genParams.AboveFuncExponent )*
                                              (1 - desiredWaterLevel);
                        }
                    }
                }
            }

            // Calculate the slope
            if( genParams.CliffSmoothing ) {
                ReportRelativeProgress( 2, "Heightmap Processing: Smoothing" );
                slopemap = Noise.CalculateSlope( Noise.GaussianBlur5X5( heightmap ) );
            } else {
                slopemap = Noise.CalculateSlope( heightmap );
            }

            // Randomize max height/depth
            float[,] altmap = null;
            if( genParams.MaxHeightVariation != 0 || genParams.MaxDepthVariation != 0 ) {
                ReportRelativeProgress( 5, "Heightmap Processing: Randomizing" );
                altmap = new float[map.Width,map.Length];
                int blendmapDetailSize = (int)Math.Log( Math.Max( genParams.MapWidth, genParams.MapLength ), 2 ) - 2;
                new Noise( rand.Next(), NoiseInterpolationMode.Cosine )
                    .PerlinNoise( altmap, Math.Min( blendmapDetailSize, 3 ), blendmapDetailSize,
                                  0.5f, 0, 0 );
                Noise.Normalize( altmap, -1, 1 );
            }

            int snowStartThreshold = snowAltitudeScaled - genParams.SnowTransition;
            int snowThreshold = snowAltitudeScaled;

            ReportRelativeProgress( 10, "Filling" );
            if( theme.AirBlock != Block.Air ) {
                map.Blocks.MemSet( (byte)theme.AirBlock );
            }
            for( int x = heightmap.GetLength( 0 ) - 1; x >= 0; x-- ) {
                for( int y = heightmap.GetLength( 1 ) - 1; y >= 0; y-- ) {
                    int level;
                    float slope;
                    if( heightmap[x, y] < desiredWaterLevel ) {
                        // for blocks below "sea level"
                        float depth = maxDepthScaled;
                        if( altmap != null ) {
                            depth += altmap[x, y] * genParams.MaxDepthVariation;
                        }
                        slope = slopemap[x, y] * depth;
                        level = genParams.WaterLevel - (int)Math.Round( Math.Pow( 1 - heightmap[x, y] / desiredWaterLevel, genParams.BelowFuncExponent ) * depth );

                        if( genParams.AddWater ) {
                            if( genParams.WaterLevel - level > 3 ) {
                                map.SetBlock( x, y, genParams.WaterLevel, theme.DeepWaterSurfaceBlock );
                            } else {
                                map.SetBlock( x, y, genParams.WaterLevel, theme.WaterSurfaceBlock );
                            }
                            for( int i = genParams.WaterLevel; i > level; i-- ) {
                                map.SetBlock( x, y, i, theme.WaterBlock );
                            }
                            for( int i = level; i >= 0; i-- ) {
                                if( level - i < theme.SeaFloorThickness ) {
//.........这里部分代码省略.........
开发者ID:fragmer,项目名称:fCraft,代码行数:101,代码来源:RealisticMapGenState.cs

示例3: PlantGiantTrees

 void PlantGiantTrees() {
     if( genParams.GiantTreeDensity <= 0 ) return;
     Map outMap = new Map( null, map.Width, map.Length, map.Height, false ) {
         Blocks = (byte[])map.Blocks.Clone()
     };
     int plantableBlocks = ComputeSurfaceCoverage( Block.Grass );
     var foresterArgs = new ForesterArgs {
         Map = map,
         Rand = rand,
         TreeCount = (int)(plantableBlocks*genParams.GiantTreeDensity/BaseGiantTreeDensity),
         Operation = Forester.ForesterOperation.Add,
         PlantOn = Block.Grass
     };
     foresterArgs.BlockPlacing += ( sender, e ) => outMap.SetBlock( e.Coordinate, e.Block );
     Forester.Generate( foresterArgs );
     map = outMap;
 }
开发者ID:fragmer,项目名称:fCraft,代码行数:17,代码来源:FloatingIslandMapGen.cs

示例4: ExpandGround

 void ExpandGround() {
     Map newMap = new Map( null, map.Width, map.Length, map.Height, false ) {Blocks = (byte[])map.Blocks.Clone()};
     for( int x = 2; x < genParams.MapWidth - 2; x++ ) {
         for( int y = 2; y < genParams.MapLength - 2; y++ ) {
             for( int z = 2; z < genParams.MapHeight - 2; z++ ) {
                 if( map.GetBlock( x, y, z ) == Block.Air ) {
                     if( HasNeighbors( x, y, z ) ) {
                         newMap.SetBlock( x, y, z, Block.Dirt );
                     }
                 } else {
                     newMap.SetBlock( x, y, z, Block.Stone );
                 }
             }
         }
         if( x%4 == 0 ) {
             int percent = x*100/map.Width;
             ReportProgress( percent/2 + 30, "Expanding (" + percent + "%)..." );
         }
     }
     map = newMap;
 }
开发者ID:fragmer,项目名称:fCraft,代码行数:21,代码来源:FloatingIslandMapGen.cs

示例5: SmoothEdges

 void SmoothEdges() {
     Map newMap = new Map( null, map.Width, map.Length, map.Height, false ) {Blocks = (byte[])map.Blocks.Clone()};
     for( int x = 1; x < genParams.MapWidth - 1; x++ ) {
         for( int y = 1; y < genParams.MapLength - 1; y++ ) {
             for( int z = 1; z < genParams.MapHeight - 1; z++ ) {
                 int sum = (map.GetBlock( x - 1, y, z ) != Block.Air ? 1 : 0) +
                           (map.GetBlock( x + 1, y, z ) != Block.Air ? 1 : 0) +
                           (map.GetBlock( x, y - 1, z ) != Block.Air ? 1 : 0) +
                           (map.GetBlock( x, y + 1, z ) != Block.Air ? 1 : 0) +
                           (map.GetBlock( x, y, z - 1 ) != Block.Air ? 1 : 0) +
                           (map.GetBlock( x, y, z + 1 ) != Block.Air ? 1 : 0);
                 if( map.GetBlock( x, y, z ) != Block.Air ) {
                     newMap.SetBlock( x, y, z, Block.White );
                 } else if( sum > 1 && map.GetBlock( x, y, z - 1 ) != Block.Air ) {
                     newMap.SetBlock( x, y, z, Block.Blue );
                 }
             }
         }
     }
     map = newMap;
 }
开发者ID:fragmer,项目名称:fCraft,代码行数:21,代码来源:FloatingIslandMapGen.cs

示例6: Generate

        public override Map Generate() {
            if( Finished ) return Result;
            try {
                ReportProgress( 0, "Clumping spheres..." );
                rand = new Random( genParams.Seed );
                map = new Map( null, genParams.MapWidth, genParams.MapLength, genParams.MapHeight, true );

                int numIslands = Math.Max( 1, (int)(map.Volume * genParams.IslandDensity / (96 * 96 * 64)) );
                Random islandCoordRand = new Random( rand.Next() );

                List<Island> islands = new List<Island>();

                for( int i = 0; i < numIslands; i++ ) {
                    Vector3I offset = new Vector3I( islandCoordRand.Next( 16, genParams.MapWidth - 16 ),
                                                    islandCoordRand.Next( 16, genParams.MapLength - 16 ),
                                                    islandCoordRand.Next( 16, genParams.MapHeight - 16 ) );
                    islands.Add( CreateIsland( offset ) );
                }
                if( Canceled ) return null;
                
                ReportProgress( 10, "Smoothing (0%)..." );
                SmoothEdges();
                if( Canceled ) return null;
                
                ReportProgress( 15, "Smoothing (50%)..." );
                SmoothEdges();
                if( Canceled ) return null;
                
                ReportProgress( 20, "Expanding..." );
                ExpandGround();
                if( Canceled ) return null;

                ReportProgress( 70, "Adding stone..." );
                for( int i = 0; i < numIslands; i++ ) {
                    MakeIslandBase( islands[i] );
                }

                ReportProgress( 75, "Planting grass..." );
                PlantGrass();
                if( Canceled ) return null;
                
                ReportProgress( 80, "Watering..." );
                for( int x = 0; x < map.Width; x++ ) {
                    for( int y = 0; y < map.Length; y++ ) {
                        map.SetBlock( x, y, 0, Block.Admincrete );
                        map.SetBlock( x, y, 1, Block.Water );
                    }
                }
                MakeWater();
                if( Canceled ) return null;
                
                ReportProgress( 85, "Planting trees..." );
                PlantGiantTrees();
                PlantTrees();
                if( Canceled ) return null;

                ReportProgress( 88, "Planting flowers..." );
                PlantFlowers();
                if( Canceled ) return null;
                
                ReportProgress( 90, "Eroding (0%)..." );
                Erode();
                if( Canceled ) return null;
                ReportProgress( 95, "Eroding (50%)..." );
                Erode();
                if( Canceled ) return null;
                
                Result = map;
                return Result;
            } finally {
                Finished = true;
                Progress = 100;
                StatusString = (Canceled ? "Canceled" : "Finished");
            }
        }
开发者ID:fragmer,项目名称:fCraft,代码行数:75,代码来源:FloatingIslandMapGen.cs


注:本文中的Map.SetBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。