Beispiel #1
0
        public void Generate(SharpNoise.Models.Plane noise_plane)
        {
            for (int x = 0; x < MineGame.chunk_size; x++)
            {
                for (int z = 0; z < MineGame.chunk_size; z++)
                {
                    for (int y = 0; y < MineGame.chunk_size; y++)
                    {
                        var pvalue = noise_plane.GetValue((chunk_x + x) / 125.5, (chunk_z + z) / 125.5);
                        var height = 5  + pvalue * 4;

                        BlockType t;
                        if ((int) height == (chunk_y + y))
                        {
                          t = BlockType.Grass;
                        }
                        else if ((int)height > (chunk_y + y))
                        {
                          t = BlockType.Dirt;
                        }
                        else
                        {
                          t = BlockType.Air;
                        }
                        var b = new Block(chunk_x + x, chunk_y + y, chunk_z + z, t);
                        b.active = (b.type != BlockType.Air);
                        blocks[x, y, z] = b;
                    }
                }

            }

              /*
            if (chunk_x > 3 || chunk_z > 3) { return; }

            Random random = new Random( (int)( 10000* noise_plane.GetValue((chunk_x) / 205.0, (chunk_z) / 205.0)));

            for (int i = 0; i <2; i++)
            {
                int tree_x = random.Next(4, 12);
                int tree_z = random.Next(4, 12);
                var tree_pvalue = noise_plane.GetValue((chunk_x + tree_x) / 200.0, (chunk_z + tree_z) / 200.0);
                var tree_height = (int)(Math.Floor(15 + tree_pvalue * 10));

                int base_tree_level = tree_height - chunk_y-1;
                if (tree_height > chunk_y && (tree_height + 7) < chunk_y + MineGame.chunk_size && tree_x > 4 && tree_x < (MineGame.chunk_size - 4) && tree_z > 4 && tree_z < (MineGame.chunk_size - 4))
                {
                    for (int m = 0; m < 8; m++)
                    {
                      int level = base_tree_level + m;
                      if (m < 7)
                      {
                        blocks[tree_x, level, tree_z].type = BlockType.Oak_Wood;
                        blocks[tree_x, level, tree_z].active = true;
                      }
                      if (m == 4 || m == 5 )
                      {
                        for (int a = -2; a < 3;a++)
                        {
                          for (int b = -2; b < 3; b++)
                          {
                             if( (a != 0 || b != 0) &&  (Math.Abs(a) + Math.Abs( b ) != 4) ){
                               blocks[tree_x + a, level, tree_z+b].type = BlockType.Oak_Leaves;
                               blocks[tree_x + a, level, tree_z+b].active = true;
                             }
                          }
                        }
                      }
                      if (m == 6 || m == 7)
                      {
                        blocks[tree_x + 1, level, tree_z].type = BlockType.Oak_Leaves;
                        blocks[tree_x + 1, level, tree_z].active = true;

                        blocks[tree_x - 1, level, tree_z].type = BlockType.Oak_Leaves;
                        blocks[tree_x - 1, level, tree_z].active = true;

                        blocks[tree_x, level, tree_z - 1].type = BlockType.Oak_Leaves;
                        blocks[tree_x, level, tree_z - 1].active = true;

                        blocks[tree_x, level, tree_z + 1].type = BlockType.Oak_Leaves;
                        blocks[tree_x, level, tree_z + 1].active = true;
                      }
                      if (m == 7)
                      {
                        blocks[tree_x, level, tree_z].type = BlockType.Oak_Leaves;
                        blocks[tree_x, level, tree_z].active = true;
                      }
                    }
                }

              }*/
        }
Beispiel #2
0
        public void Generate()
        {
            for (int latitude_offset = 0; latitude_offset < MineGame.chunk_size; latitude_offset++)
              {
            for (int longitude_offset = 0; longitude_offset < MineGame.chunk_size; longitude_offset++)
            {
              for (int height_offset = 0; height_offset < MineGame.chunk_height; height_offset++)
              {
            var block_radial_distance = (height_offset*planet.height_step + radial_distance);
            var block_latitude = latitude + latitude_offset * planet.step;
            var block_longitude = longitude + longitude_offset * planet.step;
            var pvalue = planet.noise.GetValue(block_latitude, block_longitude);
            var terrain_height = (int)( 34 * Math.Abs(pvalue));

            var equator = 25.0 * planet.equator_noise.GetValue(block_longitude/3000.0);

            BlockType t;
            if ((height_offset - terrain_height) < 1)
            {
              if (height_offset > 18)
              {
                t = BlockType.Snow;
              }
              else if(height_offset > 17)
              {
                t = BlockType.Stone;
              }
              else if (Math.Abs(block_latitude) > 50)
              {
                t = BlockType.Snow;
              }
              else if (Math.Abs(block_latitude - equator) < 7)
              {
                t = BlockType.Sand;
              }
              else
              {
                t = BlockType.Grass;
              }
            }
            else if ((int)terrain_height > block_radial_distance)
            {
              t = BlockType.Dirt;
            }
            else
            {
              t = BlockType.Air;
            }
            var b = new Block(block_latitude, block_longitude, block_radial_distance, t);
            b.active = (b.type != BlockType.Air);
            blocks[latitude_offset, longitude_offset, height_offset] = b;
              }
            }
              }
        }