예제 #1
0
 public FilteredNoise( PerlinNoise noise1, PerlinNoise noise2 ) {
     this.noise1 = noise1;
     this.noise2 = noise2;
 }
예제 #2
0
 public FilteredNoise(PerlinNoise noise1, PerlinNoise noise2)
 {
     this.noise1 = noise1;
     this.noise2 = noise2;
 }
예제 #3
0
 // fill the map with blocks based on the heightmap
 void Soil() {
     Random soilRand = new Random( random.Next() );
     PerlinNoise soilNoise1 = new PerlinNoise( soilRand, 8 );
     for( int x = 0; x < genParams.MapWidth; x++ ) {
         for( int y = 0; y < genParams.MapLength; y++ ) {
             int i7 = (int)(soilNoise1.GetNoise( x, y )/24) - 4;
             int i19 = heightmap[(x + y*genParams.MapWidth)] + waterLevel;
             int i21 = i19 + i7;
             heightmap[(x + y*genParams.MapWidth)] = Math.Max( i19, i21 );
             if( heightmap[(x + y*genParams.MapWidth)] > genParams.MapHeight - 2 )
                 heightmap[(x + y*genParams.MapWidth)] = (genParams.MapHeight - 2);
             if( heightmap[(x + y*genParams.MapWidth)] < 1 )
                 heightmap[(x + y*genParams.MapWidth)] = 1;
             for( int z = 0; z < genParams.MapHeight; z++ ) {
                 Block block = Block.Air;
                 if( z <= i19 )
                     block = Block.Dirt;
                 if( z <= i21 )
                     block = Block.Stone;
                 if( z == 0 )
                     block = Block.Lava;
                 int index = (z*genParams.MapLength + y)*genParams.MapWidth + x;
                 blocks[index] = (byte)block;
             }
         }
     }
 }
예제 #4
0
        // replaces dirt with sand, grass, or gravel
        void Grow() {
            PerlinNoise growNoise1 = new PerlinNoise( random, 8 );
            PerlinNoise growNoise2 = new PerlinNoise( random, 8 );
            for( int x = 0; x < genParams.MapWidth; x++ ) {
                for( int y = 0; y < genParams.MapLength; y++ ) {
                    int elevation = heightmap[(x + y*genParams.MapWidth)];
                    Block blockAbove = (Block)blocks[(((elevation + 1)*genParams.MapLength + y)*genParams.MapWidth + x)];
                    int index = (elevation*genParams.MapLength + y)*genParams.MapWidth + x;

                    if( blockAbove == Block.Air ) {
                        bool placeSand = growNoise1.GetNoise( x, y ) > 8;
                        if( (elevation <= waterLevel - 1) && placeSand ) {
                            blocks[index] = (byte)Block.Sand;
                        } else {
                            blocks[index] = (byte)Block.Grass;
                        }
                    } else if( ((blockAbove == Block.Water) || (blockAbove == Block.StillWater)) &&
                               (elevation <= waterLevel - 1) ) {
                        bool placeGravel = growNoise2.GetNoise( x, y ) > 12;
                        if( placeGravel ) {
                            blocks[index] = (byte)Block.Gravel;
                        }
                    }
                }
            }
        }
예제 #5
0
        // create the base heightmap
        void Raise() {
            Random raiseRand = new Random( random.Next() );
            FilteredNoise raiseNoise1 = new FilteredNoise( new PerlinNoise( raiseRand, genParams.TerrainDetailOctaves ),
                                                           new PerlinNoise( raiseRand, genParams.TerrainDetailOctaves ) );
            FilteredNoise raiseNoise2 = new FilteredNoise( new PerlinNoise( raiseRand, genParams.TerrainDetailOctaves ),
                                                           new PerlinNoise( raiseRand, genParams.TerrainDetailOctaves ) );
            PerlinNoise raiseNoise3 = new PerlinNoise( raiseRand, genParams.TerrainFeatureOctaves );

            const double scale = 1.3;
            for( int x = 0; x < genParams.MapWidth; x++ ) {
                for( int y = 0; y < genParams.MapLength; y++ ) {
                    double d2 = raiseNoise1.GetNoise( x*scale, y*scale )/6 - 4;
                    double d3 = raiseNoise2.GetNoise( x*scale, y*scale )/5 + 10 - 4;
                    double d4 = raiseNoise3.GetNoise( x, y )/8;
                    if( d4 > 0 )
                        d3 = d2;
                    double elevation = Math.Max( d2, d3 )/2;
                    if( elevation < 0 )
                        elevation *= 0.8;
                    heightmap[(x + y*genParams.MapWidth)] = (int)elevation;
                }
            }
        }