xxxxxxxxxx
29
// Does very little, simply manages the array of all the boids
class Flock {
constructor() {
// An array for all the boids
this.boids = []; // Initialize the array
}
run() {
for (let boid of this.boids) {
boid.run(this.boids); // Passing the entire list of boids to each boid individually
}
}
avoid(obstacle) {
for (let boid of this.boids) {
let d = p5.Vector.dist(boid.position, obstacle);
if (d > 0 && d < 100) {
boid.avoid(obstacle);
}
}
}
addBoid(b) {
this.boids.push(b);
}
}