コード例 #1
0
        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;
                    }
                }
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 private static GameObject[] FindNear(PointF ubic, World world)
 {
     GameObject[] temp = world.GameObjectsNear(ubic, 1);
     temp.Where(i => i != null);
     return(temp);
 }
コード例 #5
0
ファイル: Ant.cs プロジェクト: Agus-git/AntSimulation
 private GameObject[] FindNear(World world, float radius)
 {
     GameObject[] temp = world.GameObjectsNear(Position, int.Parse(radius.ToString()));
     temp.Where(i => i != null);
     return(temp);
 }