public static bool IsSmallIslandTooClose(SmallIsland _islandToAdd, SmallIsland[] _existingIslands) { int toAddX = _islandToAdd.centrePoint.x; int toAddY = _islandToAdd.centrePoint.y; foreach (SmallIsland eSI in _existingIslands) { int differenceX = Math.Abs(toAddX - eSI.centrePoint.x); int differenceY = Math.Abs(toAddY - eSI.centrePoint.y); int distanceBetweenCentreSqaured = (differenceX * differenceX) + (differenceY * differenceY); int minDistanceBetween = (eSI.Radius * 2) + (_islandToAdd.Radius * 2); int minDistanceBetweenSquared = minDistanceBetween * minDistanceBetween; if (minDistanceBetweenSquared > distanceBetweenCentreSqaured) { return(true); } } //Debug.Log("Fine"); return(false); }
public static void GenerateTinyIslands(GameMap _gameMap, Tile _tile) { //Top Left int x1 = UnityEngine.Random.Range(15, 24); int y1 = UnityEngine.Random.Range(15, 24); NoiseIslands.CreateIslandFromMultipleCircles(_gameMap, new MapPoint(x1, y1), 9, _tile); //Bottom Right int x2 = UnityEngine.Random.Range(48, 57); int y2 = UnityEngine.Random.Range(48, 57); NoiseIslands.CreateIslandFromMultipleCircles(_gameMap, new MapPoint(x2, y2), 9, _tile); //Top Right int IslandCountTR = UnityEngine.Random.Range(0, 3); if (IslandCountTR == 1) { int x = UnityEngine.Random.Range(42, 66); int y = UnityEngine.Random.Range(6, 30); NoiseIslands.CreateIslandFromMultipleCircles(_gameMap, new MapPoint(x, y), UnityEngine.Random.Range(3, 5), _tile); } else if (IslandCountTR > 1) { SmallIsland[] SmallIslands = new SmallIsland[IslandCountTR]; int i = 0; while (i < IslandCountTR) { int Attempts = 0; bool IslandGenerated = false; while (!IslandGenerated) { int x = UnityEngine.Random.Range(42, 66); int y = UnityEngine.Random.Range(6, 30); MapPoint mp = new MapPoint(x, y); int smallRadius = UnityEngine.Random.Range(3, 4); SmallIsland smallIsland = new SmallIsland(mp, smallRadius); if (!NoiseIslands.IsSmallIslandTooClose(smallIsland, SmallIslands)) { SmallIslands[i] = smallIsland; NoiseIslands.CreateIslandFromMultipleCircles(_gameMap, mp, smallRadius, _tile); IslandGenerated = true; } else { Attempts++; Debug.Log("TR Too Close || Attempt: " + Attempts); if (Attempts >= 5) { break; } } } i++; } } //Bottom Left int IslandCountBL = UnityEngine.Random.Range(0, 3); if (IslandCountBL == 1) { int x = UnityEngine.Random.Range(6, 30); int y = UnityEngine.Random.Range(42, 66); NoiseIslands.CreateIslandFromMultipleCircles(_gameMap, new MapPoint(x, y), UnityEngine.Random.Range(3, 5), _tile); } else if (IslandCountBL > 1) { SmallIsland[] SmallIslands = new SmallIsland[IslandCountBL]; int i = 0; while (i < IslandCountBL) { int Attempts = 0; bool IslandGenerated = false; while (!IslandGenerated) { int x = UnityEngine.Random.Range(6, 30); int y = UnityEngine.Random.Range(42, 66); MapPoint mp = new MapPoint(x, y); int smallRadius = UnityEngine.Random.Range(3, 4); SmallIsland smallIsland = new SmallIsland(mp, smallRadius); if (!NoiseIslands.IsSmallIslandTooClose(smallIsland, SmallIslands)) { SmallIslands[i] = smallIsland; NoiseIslands.CreateIslandFromMultipleCircles(_gameMap, mp, smallRadius, _tile); IslandGenerated = true; } else { Attempts++; Debug.Log("BL Too Close || Attempt: " + Attempts); if (Attempts >= 5) { break; } } } i++; } } }
public static void GenerateHugeIslands(GameMap _gameMap, Tile _tile) { //Top Left int x1 = UnityEngine.Random.Range(40, 65); int y1 = UnityEngine.Random.Range(40, 65); NoiseIslands.CreateIslandFromMultipleCircles(_gameMap, new MapPoint(x1, y1), 19, _tile); //Bottom Right int x2 = UnityEngine.Random.Range(135, 160); int y2 = UnityEngine.Random.Range(135, 160); NoiseIslands.CreateIslandFromMultipleCircles(_gameMap, new MapPoint(x2, y2), 19, _tile); //Top Right int IslandCountTR = UnityEngine.Random.Range(2, 6); if (IslandCountTR == 2) { SmallIsland[] SmallIslands = new SmallIsland[IslandCountTR]; int i = 0; while (i < IslandCountTR) { int Attempts = 0; bool IslandGenerated = false; while (!IslandGenerated) { int x = UnityEngine.Random.Range(120, 180); int y = UnityEngine.Random.Range(20, 80); MapPoint mp = new MapPoint(x, y); //int smallRadius = UnityEngine.Random.Range(5, 6); SmallIsland smallIsland = new SmallIsland(mp, 10); if (!NoiseIslands.IsSmallIslandTooClose(smallIsland, SmallIslands)) { SmallIslands[i] = smallIsland; NoiseIslands.CreateIslandFromMultipleCircles(_gameMap, new MapPoint(x, y), 10, _tile); IslandGenerated = true; } else { Attempts++; Debug.Log("TR Too Close || Attempt: " + Attempts); if (Attempts >= 5) { break; } } } i++; } } else if (IslandCountTR > 2) { SmallIsland[] SmallIslands = new SmallIsland[IslandCountTR]; int i = 0; while (i < IslandCountTR) { int Attempts = 0; bool IslandGenerated = false; while (!IslandGenerated) { int x = UnityEngine.Random.Range(112, 188); int y = UnityEngine.Random.Range(12, 88); MapPoint mp = new MapPoint(x, y); int smallRadius = UnityEngine.Random.Range(5, 6); SmallIsland smallIsland = new SmallIsland(mp, smallRadius); if (!NoiseIslands.IsSmallIslandTooClose(smallIsland, SmallIslands)) { SmallIslands[i] = smallIsland; NoiseIslands.CreateIslandFromMultipleCircles(_gameMap, mp, smallRadius, _tile); IslandGenerated = true; } else { Attempts++; Debug.Log("TR Too Close || Attempt: " + Attempts); if (Attempts >= 5) { break; } } } i++; } } //Bottom Left int IslandCountBL = UnityEngine.Random.Range(2, 6); if (IslandCountBL == 2) { SmallIsland[] SmallIslands = new SmallIsland[IslandCountTR]; int i = 0; while (i < IslandCountBL) { int Attempts = 0; bool IslandGenerated = false; while (!IslandGenerated) { int x = UnityEngine.Random.Range(20, 80); int y = UnityEngine.Random.Range(120, 180); MapPoint mp = new MapPoint(x, y); SmallIsland smallIsland = new SmallIsland(mp, 10); if (!NoiseIslands.IsSmallIslandTooClose(smallIsland, SmallIslands)) { SmallIslands[i] = smallIsland; NoiseIslands.CreateIslandFromMultipleCircles(_gameMap, new MapPoint(x, y), 10, _tile); IslandGenerated = true; } else { Attempts++; Debug.Log("TR Too Close || Attempt: " + Attempts); if (Attempts >= 5) { break; } } } i++; } } else if (IslandCountBL > 2) { SmallIsland[] SmallIslands = new SmallIsland[IslandCountBL]; int i = 0; while (i < IslandCountBL) { int Attempts = 0; bool IslandGenerated = false; while (!IslandGenerated) { int x = UnityEngine.Random.Range(12, 88); int y = UnityEngine.Random.Range(112, 188); MapPoint mp = new MapPoint(x, y); int smallRadius = UnityEngine.Random.Range(5, 6); SmallIsland smallIsland = new SmallIsland(mp, smallRadius); if (!NoiseIslands.IsSmallIslandTooClose(smallIsland, SmallIslands)) { SmallIslands[i] = smallIsland; NoiseIslands.CreateIslandFromMultipleCircles(_gameMap, mp, smallRadius, _tile); IslandGenerated = true; } else { Attempts++; Debug.Log("BL Too Close || Attempt: " + Attempts); if (Attempts >= 5) { break; } } } i++; } } }