Guest User

Untitled

a guest
Aug 16th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. ...
  2.     public Planet(Int32 seed)
  3.     {
  4.         this.levels = new List<Level>();
  5.         this.Seed = seed;
  6.         this.random = new Random(this.Seed);
  7.  
  8.         var width = 512;
  9.         var height = 512;
  10.  
  11.         var module = new ImplicitFractal(FractalType.FractionalBrownianMotion, BasisType.Gradient, InterpolationType.Quintic);
  12.         module.Seed = this.Seed;
  13.         module.Octaves = 1;
  14.         module.Frequency = 2.00 + 2 * (width / 256.00);
  15.         var cache = new ImplicitCache(module);
  16.  
  17.         var values = new Double[width, height];
  18.         var sw = Stopwatch.StartNew();
  19.         Mapping.Map2D(MappingMode.SeamlessXY, values, cache, new MappingRanges(), 0.00);
  20.         Console.WriteLine("Generated in : " + sw.Elapsed.TotalSeconds.ToString("0.00") + "s - " + (sw.Elapsed.TotalMilliseconds / (width * height)).ToString("0.00") + "ms per tile");
  21.         var level = new Level(width, height);
  22.         for (var y = 0; y < level.TilesHigh; y++)
  23.         {
  24.             for (var x = 0; x < level.TilesWide; x++)
  25.             {
  26.                 if (values[x, y] > 0.30)
  27.                     level.SetTile(x, y, new Tile(TileBackType.Rock, TileBaseType.Iron));
  28.                 else if (values[x, y] > 0.13)
  29.                     level.SetTile(x, y, new Tile(TileBackType.Rock, TileBaseType.Rock));
  30.                 else if (values[x, y] > 0.08)
  31.                     level.SetTile(x, y, new Tile(TileBackType.Gravel, TileBaseType.Air));
  32.                 else if (values[x, y] > 0.00)
  33.                     level.SetTile(x, y, new Tile(TileBackType.Sand, TileBaseType.Air));
  34.                 else if (values[x, y] > -0.30)
  35.                     level.SetTile(x, y, new Tile(TileBackType.Dirt, TileBaseType.Air));
  36.                 else
  37.                     level.SetTile(x, y, new Tile(TileBackType.Water, TileBaseType.Air));
  38.             }
  39.         }
  40.         this.levels.Add(level);
  41.     }
  42. ...
Advertisement
Add Comment
Please, Sign In to add comment