Ejemplo n.º 1
0
 public FilteredNoise( [NotNull] PerlinNoise noise1, [NotNull] PerlinNoise noise2 )
 {
     if( noise1 == null ) throw new ArgumentNullException( "noise1" );
     if( noise2 == null ) throw new ArgumentNullException( "noise2" );
     this.noise1 = noise1;
     this.noise2 = noise2;
 }
Ejemplo n.º 2
0
        void Raise()
        {
            FilteredNoise raiseNoise1 = new FilteredNoise( new PerlinNoise( random, TerrainDetailOctaves ),
                                                           new PerlinNoise( random, TerrainDetailOctaves ) );
            FilteredNoise raiseNoise2 = new FilteredNoise( new PerlinNoise( random, TerrainDetailOctaves ),
                                                           new PerlinNoise( random, TerrainDetailOctaves ) );
            PerlinNoise raiseNoise3 = new PerlinNoise( random, TerrainFeatureOctaves );

            // raising
            const double scale = 1.3;
            for( int x = 0; x < mapWidth; x++ ) {
                for( int y = 0; y < mapLength; y++ ) {
                    double d2 = raiseNoise1.GetNoise( x * scale, y * scale ) / 6.0 - 4;
                    double d3 = raiseNoise2.GetNoise( x * scale, y * scale ) / 5.0 + 10.0 - 4;
                    double d4 = raiseNoise3.GetNoise( x, y ) / 8.0;
                    if( d4 > 0 )
                        d3 = d2;
                    double elevation = Math.Max( d2, d3 ) / 2.0;
                    if( elevation < 0 )
                        elevation *= 0.8;
                    heightmap[( x + y * mapWidth )] = (int)elevation;
                }
            }
        }
Ejemplo n.º 3
0
 void Soil()
 {
     PerlinNoise soilNoise1 = new PerlinNoise( random, 8 );
     for( int x = 0; x < mapWidth; x++ ) {
         for( int y = 0; y < mapLength; y++ ) {
             int i7 = (int)( soilNoise1.GetNoise( x, y ) / 24.0 ) - 4;
             int i19 = heightmap[( x + y * mapWidth )] + waterLevel;
             int i21 = i19 + i7;
             heightmap[( x + y * mapWidth )] = Math.Max( i19, i21 );
             if( heightmap[( x + y * mapWidth )] > mapHeight - 2 )
                 heightmap[( x + y * mapWidth )] = ( mapHeight - 2 );
             if( heightmap[( x + y * mapWidth )] < 1 )
                 heightmap[( x + y * mapWidth )] = 1;
             for( int z = 0; z < 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 * mapLength + y ) * mapWidth + x;
                 blocks[index] = (byte)block;
             }
         }
     }
 }
Ejemplo n.º 4
0
        void Grow()
        {
            PerlinNoise growNoise1 = new PerlinNoise( random, 8 );
            PerlinNoise growNoise2 = new PerlinNoise( random, 8 );
            for( int x = 0; x < mapWidth; x++ ) {
                for( int y = 0; y < mapLength; y++ ) {
                    int elevation = heightmap[( x + y * mapWidth )];
                    Block blockAbove = (Block)blocks[( ( ( elevation + 1 ) * mapLength + y ) * mapWidth + x )];
                    int index = ( elevation * mapLength + y ) * mapWidth + x;

                    if( blockAbove == Block.Air ) {
                        bool placeSand = growNoise1.GetNoise( x, y ) > 8.0;
                        if( ( elevation <= mapHeight / 2 - 1 ) && placeSand ) {
                            blocks[index] = (byte)Block.Sand;
                        } else {
                            blocks[index] = (byte)Block.Grass;
                        }
                    } else if( ( ( blockAbove == Block.Water ) || ( blockAbove == Block.StillWater ) ) && ( elevation <= mapHeight / 2 - 1 ) ) {
                        bool placeGravel = growNoise2.GetNoise( x, y ) > 12.0;
                        if( placeGravel ) {
                            blocks[index] = (byte)Block.Gravel;
                        }
                    }
                }
            }
        }