public static void SpawnOn(World world, PointF pos, double intensity = 100) { if (intensity > 100) { intensity = 100; } Pheromone[] neighbours = world.GameObjectsNear(pos) .Select(each => each as Pheromone) .Where(p => p != null) .ToArray(); if (neighbours.Length == 0) { // No objects there Pheromone clone = new Pheromone(intensity); clone.Position = pos; world.Add(clone); } else { foreach (Pheromone p in neighbours) { if (p.Intensity < intensity) { p.Intensity = intensity; } } } }
private IEnumerable <T> FindNear <T>(World world, float radius) where T : GameObject { List <T> result = new List <T>(); for (float x = Position.X - radius; x <= Position.X + radius; x++) { for (float y = Position.Y - radius; y <= Position.Y + radius; y++) { result.AddRange(world .GameObjectsNear(new PointF(x, y)) .Select(t => t as T) .Where(t => t != null)); } } return(result); }
private IEnumerable <T> FindNear <T>(World world, float radius) where T : GameObject { List <T> result = new List <T>(); for (float x = Position.X - radius; x <= Position.X + radius; x++) { for (float y = Position.Y - radius; y <= Position.Y + radius; y++) { int pointX = (int)Math.Round(x);//redondeo int pointY = (int)Math.Round(y); result.AddRange(world .GameObjectsNear(pointX, pointY) .Select(t => t as T) .Where(t => t != null)); } } return(result); }
private static GameObject[] FindNear(PointF ubic, World world) { GameObject[] temp = world.GameObjectsNear(ubic, 1); temp.Where(i => i != null); return(temp); }
private GameObject[] FindNear(World world, float radius) { GameObject[] temp = world.GameObjectsNear(Position, int.Parse(radius.ToString())); temp.Where(i => i != null); return(temp); }