xxxxxxxxxx
46
let fish = [];
let targets = [];
let prey;
let whale;
function preload() {
whale = loadImage('otter.png');
}
function setup() {
createCanvas(600, 400);
fish = new Vehicle(width / 2, height / 2);
//prey = new Target(random(width), random(he))
// Initialize the targets
for (let i = 0; i < 2000; i++) {
targets.push(new Target(random(width), random(height)));
}
}
function draw() {
background(0);
// Check if the fish encounters any targets
for (let i = targets.length - 1; i >= 0; i--) {
if (dist(fish.pos.x, fish.pos.y, targets[i].pos.x, targets[i].pos.y) < fish.r) {
// Remove the target and add a new one
targets.splice(i, 1);
// Increase the fish size
//fish.r += 2;
}
}
fish.wander();
fish.update();
fish.show();
fish.edges();
// Display the targets
for (let target of targets) {
target.show();
}
}