示例#1
0
        public static Vector2 Avoidance(Boid boid, List <Boid> boids)
        {
            var radius = 25;
            var avoid  = new Vector2();
            var count  = 0;

            foreach (Boid other in boids)
            {
                if (Math.Abs((boid.cellPosition - other.cellPosition).Length()) > 1)
                {
                    continue;
                }

                var distance = Vector2.Distance(boid.position, other.position);

                if (distance < radius && distance > 0)
                {
                    avoid += (boid.position - other.position) / (float)Math.Pow(distance, 2);
                    count++;
                }
            }

            if (count != 0)
            {
                avoid /= count;
            }

            if (avoid.Length() > 0)
            {
                avoid.Normalize();
            }
            else
            {
                avoid = Vector2.Zero;
            }

            return(avoid);
        }
示例#2
0
 public void Remove(Boid boid)
 {
     boids.Remove(boid);
 }
示例#3
0
 public void Add(Boid boid)
 {
     boids.Add(boid);
 }