private MapData GenerateSpecials(MapData _mapData, int _mapChunkSize, float _heigtCurveStartValue) { ObstacleData[,] obstacleData = new ObstacleData[_mapChunkSize, _mapChunkSize]; //spawn a random amount of island at random locations in the chunk. int randomSpecialCount = Random.Range(minSpecialAmount, maxSpecialAmount); for (int i = 0; i < randomSpecialCount; i++) { Vector2 spawnPos = new Vector2(Random.Range(specialGroundClearingSize, _mapChunkSize - specialGroundClearingSize), Random.Range(specialGroundClearingSize, _mapChunkSize - specialGroundClearingSize)); //if the spawnPos we generated is not high enough, generate a new one until we have a good one while (_mapData.noiseMap[(int)spawnPos.x, (int)spawnPos.y] >= _heigtCurveStartValue) { spawnPos = new Vector2(Random.Range(specialGroundClearingSize, _mapChunkSize - specialGroundClearingSize), Random.Range(specialGroundClearingSize, _mapChunkSize - specialGroundClearingSize)); } _mapData = NoiseEditor.FlattenNoiseArea(_mapData, 0, true, EnumTypes.FigureMode.Circle, spawnPos, specialGroundClearingSize, _mapChunkSize); obstacleData[(int)spawnPos.x, (int)spawnPos.y].nodeValue = Mathf.FloorToInt((obstacleTypes.Length - 1) * Random.Range(0, 0.99f)) + 1; } _mapData.obstacleData = obstacleData; obstacleData = null; return(_mapData); }
private static void Init() { NoiseEditor window = (NoiseEditor)GetWindow(typeof(NoiseEditor)); window.Show(); path = Application.dataPath + "/Textures/Noise.png"; }
public MapData GenerateIslands(MapData _mapData, int _mapChunkSize, float _heigtCurveStartValue) { ObstacleData[,] obstacleData = new ObstacleData[_mapChunkSize, _mapChunkSize]; float[,] oldNoiseMap = new float[_mapChunkSize, _mapChunkSize]; System.Array.Copy(_mapData.noiseMap, oldNoiseMap, _mapData.noiseMap.GetLength(0) * _mapData.noiseMap.GetLength(1)); //edits the noise to be completely sea for (int y = 0; y < _mapChunkSize; y++) { for (int x = 0; x < _mapChunkSize; x++) { _mapData.noiseMap[x, y] = 1f; } } List <Vector2> landNeighbours = new List <Vector2>(); for (int i = 0; i < _mapData.directNeighbourCoords.Count; i++) { if (MapGenerator.mapDataContainer[_mapData.directNeighbourCoords[i]].levelMode == EnumTypes.BiomeMode.Land) { landNeighbours.Add(_mapData.directNeighbourCoords[i]); } } islandsChunkContainer.Add(_mapData.coordinate, new List <IslandData>()); //spawn a random amount of island at random locations in the chunk. int randomIslandCount = Random.Range(minIslandsCount, maxIslandsCount); for (int i = 0; i < randomIslandCount; i++) { int randomSize = Random.Range(minIslandsSize, maxIslandSize); Vector2 spawnPos = new Vector2(Random.Range(randomSize, _mapChunkSize - randomSize), Random.Range(randomSize, _mapChunkSize - randomSize)); _mapData = NoiseEditor.FlattenCircleRandomized(_mapData, 0, true, EnumTypes.FigureMode.Circle, spawnPos, randomSize, _mapChunkSize, Random.Range(minIslandRandomizedForm, maxIslandRandomizedForm)); if (islandSpecialSpawnChange > Random.Range(0, 0.99f)) { obstacleData[(int)spawnPos.x, (int)spawnPos.y].nodeValue = 2; } MakeIslandConnections(spawnPos, pathWidth, _mapData, _mapChunkSize); if (landNeighbours.Count > 0) { MakeLandConnection(spawnPos, _mapData.coordinate, landNeighbours[Random.Range(0, landNeighbours.Count - 1)], pathWidth, _mapChunkSize); } } _mapData.obstacleData = obstacleData; return(_mapData); }
public MapData GenerateEnvironment(MapData _mapData, int _mapChunkSize) { //tweak the first chunk to have a circle in the middle so the player has room to start if (_mapData.coordinate == Vector2.zero) { _mapData = NoiseEditor.FlattenCircleRandomized(_mapData, 0, true, EnumTypes.FigureMode.Circle, new Vector2(_mapChunkSize / 2, _mapChunkSize / 2), _mapChunkSize / 2, _mapChunkSize, 10); } _mapData = ManageChunkGradient(_mapData, smoothSizeDivider, _mapChunkSize); return(_mapData); }
private void MakeLandConnection(Vector2 _ourIslandLocalCoordinates, Vector2 _ourChunkCoordinates, Vector2 _destinationChunkCoordinates, int _pathWidth, int _mapChunkSize) { int destinationClearSize = 10; Vector2 localDestination = new Vector2(Random.Range(destinationClearSize, _mapChunkSize - destinationClearSize), Random.Range(destinationClearSize, _mapChunkSize - destinationClearSize)); MapData destinationMapdata = MapGenerator.mapDataContainer[_destinationChunkCoordinates]; destinationMapdata = NoiseEditor.FlattenNoiseArea(destinationMapdata, 0, true, EnumTypes.FigureMode.Circle, localDestination, destinationClearSize, _mapChunkSize); MapGenerator.mapDataContainer[_destinationChunkCoordinates] = destinationMapdata; Paths.CreatePathChunksOverflow(_ourChunkCoordinates, _destinationChunkCoordinates, _ourIslandLocalCoordinates, localDestination, 0, _pathWidth, pathSmoothness, false, _mapChunkSize); }
public MapData SmoothToCornerNeighbours(MapData _mapData, Vector2 _dir, int _sizeDivider, int _mapChunkSize) { if (_dir.x != 0) { _mapData.noiseMap = NoiseEditor.SmoothCornerDirX(_mapData.noiseMap, (int)_dir.x, _sizeDivider, _mapChunkSize); } if (_dir.y != 0) { _mapData.noiseMap = NoiseEditor.SmoothCornerDirY(_mapData.noiseMap, (int)_dir.y, _sizeDivider, _mapChunkSize); } return(_mapData); }