public void Spawn() { while (coins.Count < 2) { int index = Config.rand.Next(world.Tiles.Count()); bool colliding = false; foreach (Tile t in world.Tiles) { if (t != world.Tiles[index]) { if (world.Tiles[index].Rect.Right > 0 && world.Tiles[index].Rect.Left < Config.screenW) { Rectangle testRect = new Rectangle(world.Tiles[index].Rect.X + 5, world.Tiles[index].Rect.Y + 5 - Tile.Size, world.Tiles[index].Rect.Width - 10, world.Tiles[index].Rect.Height - 10); Rectangle testRect2 = testRect; Rectangle testRect3 = testRect; testRect2.X -= Tile.Size; testRect3.X += Tile.Size; if (t.Rect.Intersects(testRect) || t.Rect.Intersects(testRect2) || t.Rect.Intersects(testRect3)) { colliding = true; } } } } if(!colliding) { bool tooClose = false; foreach (Player p in world.Players) { Vector2 v = new Vector2(world.Tiles[index].Rect.Center.X, world.Tiles[index].Rect.Center.Y); float dist = Vector2.Distance(v, p.Position); if (dist < 150) { tooClose = true; break; } } if (tooClose) { break; } else { Coin e = new Coin(world.Tiles[index].Rect.Center.X, world.Tiles[index].Rect.Y - Coin.size - offset, world); coins.Add(e); return; } } } }
public void Remove(Coin e) { toRemove.Add(e); }