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


C# Map.SetBlock方法代码示例

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


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

示例1: 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

示例2: GenerateMap

        public Map GenerateMap()
        {
            Map map = new Map(null, args.MapWidth, args.MapLength, args.MapHeight, true);

            // Match water coverage
            float desiredWaterLevel = .5f;
            if (args.MatchWaterCoverage)
            {
                ReportProgress(2, "Heightmap Processing: Matching water coverage");
                desiredWaterLevel = Noise.FindThreshold(heightmap, args.WaterCoverage);
            }

            // Calculate above/below water multipliers
            float aboveWaterMultiplier = 0;
            if (desiredWaterLevel != 1)
            {
                aboveWaterMultiplier = (args.MaxHeight / (1 - desiredWaterLevel));
            }

            // Apply power functions to above/below water parts of the heightmap
            if (args.BelowFuncExponent != 1 || args.AboveFuncExponent != 1)
            {
                ReportProgress(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, args.BelowFuncExponent) * desiredWaterLevel;
                        }
                        else
                        {
                            float normalizedHeight = (heightmap[x, y] - desiredWaterLevel) / (1 - desiredWaterLevel);
                            heightmap[x, y] = desiredWaterLevel + (float)Math.Pow(normalizedHeight, args.AboveFuncExponent) * (1 - desiredWaterLevel);
                        }
                    }
                }
            }

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

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

            int snowStartThreshold = args.SnowAltitude - args.SnowTransition;
            int snowThreshold = args.SnowAltitude;

            ReportProgress(10, "Filling");
            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)
                    {
                        float depth = args.MaxDepth;
                        if (altmap != null)
                        {
                            depth += altmap[x, y] * args.MaxDepthVariation;
                        }
                        slope = slopemap[x, y] * depth;
                        level = args.WaterLevel - (int)Math.Round(Math.Pow(1 - heightmap[x, y] / desiredWaterLevel, args.BelowFuncExponent) * depth);

                        if (args.AddWater)
                        {
                            if (args.WaterLevel - level > 3)
                            {
                                map.SetBlock(x, y, args.WaterLevel, bDeepWaterSurface);
                            }
                            else
                            {
                                map.SetBlock(x, y, args.WaterLevel, bWaterSurface);
                            }
                            for (int i = args.WaterLevel; i > level; i--)
                            {
                                map.SetBlock(x, y, i, bWater);
                            }
                            for (int i = level; i >= 0; i--)
                            {
                                if (level - i < SeaFloorThickness)
                                {
//.........这里部分代码省略.........
开发者ID:EricKilla,项目名称:LegendCraft,代码行数:101,代码来源:MapGenerator.cs

示例3: 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

示例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: 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

示例6: DoGenerate

        internal static void DoGenerate( Map map, Player player, string mode, string filename, Random rand, bool hollow )
        {
            switch( mode ) {
                case "flatgrass":
                    player.Message( "Generating flatgrass map..." );
                    GenerateFlatgrass( map, hollow );

                    if( map.Save( filename ) ) {
                        player.Message( "Map generation: Done." );
                    } else {
                        player.Message( Color.Red, "An error occured while generating the map." );
                    }
                    break;

                case "lag":
                    player.Message( "Generating laggy map..." );
                    for( int x = 0; x < map.widthX; x+=2 ) {
                        for( int y = 0; y < map.widthY; y+=2 ) {
                            for( int h = 0; h < map.widthY; h+=2 ) {
                                map.SetBlock( x, y, h, Block.Lava );
                            }
                        }
                    }

                    if( map.Save( filename ) ) {
                        player.Message( "Map generation: Done." );
                    } else {
                        player.Message( Color.Red, "An error occured while generating the map." );
                    }
                    break;

                case "empty":
                    player.Message( "Generating empty map..." );
                    map.MakeFloodBarrier();

                    if( map.Save( filename ) ) {
                        player.Message( "Map generation: Done." );
                    } else {
                        player.Message( Color.Red, "An error occured while generating the map." );
                    }

                    break;

                case "hills":
                    player.Message( "Generating terrain..." );
                    Tasks.Add( MapGenerator.GenerationTask, new MapGenerator( rand, map, player, filename,
                                                                              1, 1, 0.5, 0.5, 0, 0.5, hollow ), false );
                    break;

                case "mountains":
                    player.Message( "Generating terrain..." );
                    Tasks.Add( MapGenerator.GenerationTask, new MapGenerator( rand, map, player, filename,
                                                                              4, 1, 0.5, 0.5, 0.1, 0.5, hollow ), false );
                    break;

                case "lake":
                    player.Message( "Generating terrain..." );
                    Tasks.Add( MapGenerator.GenerationTask, new MapGenerator( rand, map, player, filename,
                                                                              1, 0.6, 0.9, 0.5, -0.35, 0.55, hollow ), false );
                    break;

                case "island":
                    player.Message( "Generating terrain..." );
                    Tasks.Add( MapGenerator.GenerationTask, new MapGenerator( rand, map, player, filename,
                                                                              1, 0.6, 1, 0.5, 0.3, 0.35, hollow ), false );
                    break;

                default:
                    player.Message( "Unknown map generation mode: " + mode );
                    break;
            }
        }
开发者ID:asiekierka,项目名称:afCraft,代码行数:72,代码来源:MapCommands.cs

示例7: GenerateFlatgrass

        internal static void GenerateFlatgrass( Map map, bool hollow )
        {
            for ( int i = 0; i < map.widthX; i++ ) {
                for ( int j = 0; j < map.widthY; j++ ) {
                    if ( !hollow ) {
                        for ( int k = 1; k < map.height / 2 - 1; k++ ) {
                            if ( k < map.height / 2 - 5 ) {
                                map.SetBlock( i, j, k, Block.Stone );
                            } else {
                                map.SetBlock( i, j, k, Block.Dirt );
                            }
                        }
                    }
                    map.SetBlock( i, j, map.height / 2 - 1, Block.Grass );
                }
            }

            map.MakeFloodBarrier();
        }
开发者ID:asiekierka,项目名称:afCraft,代码行数:19,代码来源:MapCommands.cs

示例8: setIgloo

        public void setIgloo( Map Map, int xIn, int yIn, int zIn)
        {
            int width = rand.Next( 15, 30 );
            int height = rand.Next( 15, 30 );
            for ( int x = -width; x <= width; x++ )
                for ( int y = height; y >= -height; y-- )
                    for ( int z = -width; z <= width; z++ ) {
                        if ( y == height || ( Math.Abs( x ) == width && Math.Abs( z ) == width && y >= 0 ) ) {
                           Map.SetBlock( x + xIn, y + yIn, z + zIn, Block.Stone);
                           Map.SetBlock( x + xIn, y + yIn + 1, z + zIn, Block.Admincrete );
                        }

                        if ( y >= 1 && ( ( Math.Abs( x ) == width ) ^ ( Math.Abs( z ) == width ) ) )
                            Map.SetBlock( x + xIn, y + yIn, z + zIn, Block.Gravel );

                        if ( y > 0 && y < height && Math.Abs( z ) < width && Math.Abs( x ) < width )
                            Map.SetBlock( x + xIn, y + yIn, z + zIn, Block.Air ); //unsure

                        if ( y == -1 || y == 0 )
                           Map.SetBlock( x + xIn, y + yIn, z + zIn, Block.Gray );

                        if ( y < -1 ) {
                            if ( ( Math.Abs( x ) == width || Math.Abs( z ) == width ))
                                Map.SetBlock( x + xIn, y + yIn, z + zIn, Block.Brick );
                        }
                    }
        }
开发者ID:GlennMR,项目名称:800craft,代码行数:27,代码来源:MapGenerator.cs

示例9: 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,代码来源:MapGenerator.cs


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