public static List <Bush> generateBushes(CreatureSpawn[] spawns) { List <Bush> obstacles = new List <Bush>(); // bushes below the lane int posX = 50; int bottomBushCount = (int)(Const.random.NextDouble() * 4 + 1); for (int i = 0; i < bottomBushCount; i++) { posX = (int)(Const.random.NextDouble() * ((910 - posX) / (bottomBushCount - i)) + posX); if (posX > 910) { break; } obstacles.Add(Factories.generateBush(new Point(posX, 720))); obstacles.Add(Factories.generateBush(new Point(1920 - posX, 720))); posX += 100; } // bushes above the lane posX = 50; bottomBushCount = (int)(Const.random.NextDouble() * 2 + 2); for (int i = 0; i < bottomBushCount; i++) { posX = (int)(Const.random.NextDouble() * ((910 - posX) / (bottomBushCount - i)) + posX); if (posX > 910) { break; } obstacles.Add(Factories.generateBush(new Point(posX, 380))); obstacles.Add(Factories.generateBush(new Point(1920 - posX, 380))); posX += 100; } int extraBushes = (spawns.Length); for (int i = 0; i < extraBushes; i++) { int posY = (int)spawns[i].y; posX = (int)spawns[i].x; spawnExtraBushes(posX - 150, posY - 150, posX + 150, posY + 150, obstacles); } extraBushes = (int)(Const.random.NextDouble() * 4); for (int i = 0; i < extraBushes; i++) { spawnExtraBushes(Const.MAPWIDTH / 2 - 300, 50, Const.MAPWIDTH / 2 + 300, 300, obstacles); } return(obstacles); }
static void spawnExtraBushes(int startX, int startY, int endX, int endY, List <Bush> bushes) { for (int i = 0; i < 10; i++) { int posX = (int)(Const.random.NextDouble() * (endX - startX) + startX); int posY = (int)(Const.random.NextDouble() * (endY - startY) + startY); if (posX < Const.BUSHRADIUS || posY < Const.BUSHRADIUS || posX > Const.MAPWIDTH - Const.BUSHRADIUS || posY > Const.MAPHEIGHT - Const.BUSHRADIUS) { continue; } Point newBush = new Point(posX, posY); bool isOverlapping = false; foreach (Bush bush in bushes) { if (bush.Distance(newBush) <= bush.radius * 2) { isOverlapping = true; } } if (!isOverlapping) { if (Math.Abs(posX - center) < Const.BUSHRADIUS) { bushes.Add(Factories.generateBush(new Point(center, posY))); } else { bushes.Add(Factories.generateBush(new Point(posX, posY))); bushes.Add(Factories.generateBush(new Point(1920 - posX, posY))); } break; } } }