public PlanetSurface(int sizeX, int sizeY, GameData data, Random rng) { TileGrid = new Tile[sizeX, sizeY]; ProceduralHeightmap map = new ProceduralHeightmap(sizeX, sizeY, -2000, 6000, 0.55, 0.0, true, false); map.Generate(rng); for (int x = 0; x < sizeX; x++) { for (int y = 0; y < sizeY; y++) { int altitude = (int)map.Altitude[x, y];// +rng.Next(-500, 500); Tile tile = new Tile(this, x, y, altitude, data.Biomes["Grass"], rng); TileGrid[x, y] = tile; if (altitude > 0) { if (tile.Temperature <= 0) { tile.SetBiome(data.Biomes["Snow"], rng); } else if (altitude > 2000) { tile.SetBiome(data.Biomes["Rock"], rng); } //else if (tile.Temperature >= 25) // tile.SetBiome(data.Biomes["Steppe"], rng); } else { if (tile.Temperature >= -2) { tile.SetBiome(data.Biomes["Sea"], rng); } else { tile.SetBiome(data.Biomes["Ice"], rng); } } } } foreach (Tile tile in TileGrid) { tile.InitializeNeighbors(); } }
public void Regenerate(int width, int height, Random random) { Creatures.Clear(); ProceduralHeightmap heightmap = new ProceduralHeightmap(width, height, 0, 1, 0.65, 0.05, false, false, false); heightmap.Generate(random); Tiles = new Tile[width, height]; for (ushort x = 0; x < width; x++) { for (ushort y = 0; y < height; y++) { Terrain terrain = Mods.Terrains["Grass"]; double altitude = heightmap.GetAltitude(x, y); if (altitude < 0) { terrain = Mods.Terrains["Water"]; } else if (altitude > 0.5) { terrain = Mods.Terrains["Rock"]; } else if (altitude < 0.1 || random.NextDouble() < 0.25) { terrain = Mods.Terrains["Dirt"]; } Tiles[x, y] = new Tile(this, x, y, terrain, random); if (terrain != Mods.Terrains["Water"] && random.NextDouble() < 0.01) { Creatures.Add(new Creature(this, x, y, random)); } } } for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Tiles[x, y].InitializeNeighbors(); } } }
public void GeneratePlanet() { if (Map != null) { Map.Dispose(); } Map = new Texture2D(Game.GraphicsDevice, Width, Height); Color[] data = new Color[Width * Height]; /* * double[,] heightmap = new DiamondSquare(RNG, Width, Height, 1, 0.7, true, false).GenerateHeightmap(); * //heightmap = HydraulicErosion(heightmap, 2); * double heightmapWidth = heightmap.GetUpperBound(0); * double heightmapHeight = heightmap.GetUpperBound(1); * double widthRatio = heightmapWidth / (double)Width; * double heightRatio = heightmapHeight / (double)Height; */ int baseHeight = -500; int altitudeScale = 2500; int latitudeBonus = -1000; int sealevel = 0;// RNG.Next(-10000, 10000); ProceduralHeightmap planet = new ProceduralHeightmap(Width, Height, baseHeight, altitudeScale, 0.65, 0.1, true, false, false); //ProceduralPlanet planet = new ProceduralPlanet(Width, Height, baseHeight, altitudeScale, 0.65, 0.1); planet.Generate(RNG); for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { /* * int x2 = (int)Math.Round((x) * widthRatio); * int y2 = (int)Math.Round((y) * heightRatio); */ double latitude = (double)Math.Abs(y * 2 - Height) / Height; double altitude = baseHeight + planet.GetAltitude(x, y) + latitude * latitudeBonus; double temperature = 30 - 70 * latitude * latitude - 0.01 * altitude; if (altitude > sealevel) { if (temperature > -0) { if (altitude > 2000) { data[x + y * Width] = Color.SlateGray * (float)((altitude + altitudeScale) / (altitudeScale * 2)); } //else if (altitude > 3000) // data[x + y * Width] = Color.BurlyWood * (float)((altitude + altitudeScale) / (altitudeScale * 2)); //else if (altitude > 1000) // data[x + y * Width] = Color.YellowGreen * (float)((altitude + altitudeScale) / (altitudeScale * 2)); //else if (altitude < 100) // data[x + y * Width] = Color.SandyBrown * (float)((altitude + altitudeScale) / (altitudeScale * 2)); else { data[x + y * Width] = Color.ForestGreen * (float)((altitude + altitudeScale) / (altitudeScale * 2)); } } else { data[x + y * Width] = Color.Snow * (float)((altitude + altitudeScale) / (altitudeScale * 2)); } } else { //if (altitude > -1000 && temperature > 20) // data[x + y * Width] = Color.DarkCyan * (float)((altitude + altitudeScale) / (altitudeScale)); //else if (temperature > 0) if (temperature > -0) { data[x + y * Width] = Color.Navy * (float)((altitude + altitudeScale) / (altitudeScale)); } else { //data[x + y * Width] = Color.DarkCyan * (float)((altitude / 2 + altitudeScale) / (altitudeScale)); data[x + y * Width] = Color.Snow * (float)((altitude + altitudeScale) / (altitudeScale * 2)); } } } } for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { data[x + y * Width] = ColorExtensions.Average(GetColors(data, x, y)); } } Map.SetData(data); }