示例#1
0
 public void Quarry(Point centralPoint, float widthOfSearch, List <Neighbour> found)
 {
     if (!IntersectsWithRect(centralPoint.loc.X, centralPoint.loc.Y, widthOfSearch))
     {
         return;
     }
     else
     {
         colour = new Vector3(1, 1, 0);
         foreach (Point other in points)
         {
             if (centralPoint != other && Contains(other.loc, new Vector2(centralPoint.loc.X, centralPoint.loc.Y), new Vector2(widthOfSearch, widthOfSearch)))
             {
                 found.Add(new Neighbour(other, Vector2.Distance(centralPoint.loc, other.loc)));
             }
         }
     }
     if (isDivided)
     {
         topleft.Quarry(centralPoint, widthOfSearch, found);
         topright.Quarry(centralPoint, widthOfSearch, found);
         botleft.Quarry(centralPoint, widthOfSearch, found);
         botright.Quarry(centralPoint, widthOfSearch, found);
     }
 }
示例#2
0
        public void SeekFood(QTree foodQTree)
        {
            foreach (var ant in ants)
            {
                if (!ant.isCarryingFood)
                {
                    List <Neighbour> neibs = new List <Neighbour>();
                    foodQTree.Quarry(new Point(ant.loc + ant.vel.Normalized() * ant.size * 1.5f), ant.size * 3.0f, neibs);

                    if (neibs.Count != 0)
                    {
                        Neighbour minNeib = neibs[0];
                        float     minDist = Vector2.Distance(neibs[0].point.loc, ant.loc);

                        foreach (var n in neibs)
                        {
                            float dist = Vector2.Distance(n.point.loc, ant.loc);
                            if (dist < minDist)
                            {
                                minDist = dist;
                                minNeib = n;
                            }
                        }

                        if (minDist < ant.size)
                        {
                            ant.isCarryingFood = true;
                            ant.vel           *= -1;
                        }
                        else
                        {
                            ant.Steer(minNeib.point.loc);
                        }
                    }
                }
            }
        }