public static void StartGame() { if (!wasCreate) { int w = 100, h = 100, seed = 0; byte sea = 127; byte[] ha = MyNoise.GetMap(h, w, seed, 0.5f, NoiseType.ContinentAlgorithm); MainMenu.CreateMiniMap(sea, ha, w, h); Create(h, w, seed, sea, ha); } Main.instance.StartGame(seaLevel, terrainMask, terrainNormalMask, terrainIndexes, heightArray, regionIndex, regions, states, river); }
/// <summary> /// инициализация типов террейна и создание рек /// </summary> static void CreateTerrein() { waterArray = MyNoise.GetNoisePerlin(h, w, seed ^ (seed * 1000)); float elevation = 1f / (maxHeight - seaLevel); for (int i = 0; i < h * w; i++) { if (heightArray[i] <= seaLevel) { continue; } terrainIndexes[i] = TerId(waterArray[i] / 255f, (heightArray[i] - seaLevel) * elevation); } for (int i = 0; i < h; i++) { for (int j = 0, t; j < w; j++) { t = terrainIndexes[i * w + j]; terrainMask[t / 4].SetPixel(j, i, rgba[t % 4]); terrainNormalMask[t / 4].SetPixel(j, i, rgba[t % 4]); for (int k = 0; k < 4; k++) { if (k != t / 4) { terrainMask[k].SetPixel(j, i, rgba[4]); terrainNormalMask[k].SetPixel(j, i, rgba[4]); } } } } for (int i = 0; i < h; i += 20) { for (int j = 0; j < w; j += 20) { int x = j + (int)(20 * Random.value), y = i + (int)(20 * Random.value); if (heightArray[y * w + x] > seaLevel) { List <Vector2Int> path = AddRiver(y, x); if (path != null && path.Count >= 3) { river.Add(path); } } } } }
public void GenerateMap() { //float[,] noiseMap = Noise.GenerateNoiseMap(mapWidth, mapHeight, seed, noiseScale, octaves, persistance, lacunarity, offset); MyNoise noise = new MyNoise(seed, noiseScale, octaves, persistance, lacunarity); Island island = new Island(new Vector2(0, 0), 200f, noise); float viewSize = 300; float[,] noiseMap = island.getHeightMap(mapWidth, mapHeight, viewSize, viewSize, new Vector2(-viewSize / 2f + offset.x, -viewSize / 2f + offset.y)); Color[] colorMap = new Color[mapWidth * mapHeight]; for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { float currentHeight = noiseMap[x, y]; for (int i = 0; i < regions.Length; i++) { if (currentHeight <= regions[i].height) { colorMap[y * mapWidth + x] = regions[i].color; break; } } } } MapDisplay display = FindObjectOfType <MapDisplay>(); switch (drawMode) { case DrawMode.noiseMap: display.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap)); break; case DrawMode.colorMap: display.DrawTexture(TextureGenerator.TextureFromColormap(colorMap, mapWidth, mapHeight)); break; case DrawMode.texturedColorMap: display.DrawTexture(TextureGenerator.TextureFromColormap(colorMap, mapWidth, mapHeight, baseTexture, 150f)); break; } }
public Island(Vector2 _position, float _radius, MyNoise _noise) { noise = _noise; position = _position; radius = _radius; }
//private int seed; //private float noiseScale; //private Vector2 offset; public Island(Vector2 _position, float _radius, int _seed, float _noiseScale) { position = _position; radius = _radius; noise = new MyNoise(_seed, _noiseScale, 4, 0.5f, 2f); }