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); }
public void Remove(Boid boid) { boids.Remove(boid); }
public void Add(Boid boid) { boids.Add(boid); }