xxxxxxxxxx
35
let find = false;
let d;
let vx = 3, vy = 3;
function stalking(bubble, b){
if(d <= 400 && b.d <= bubble.d){
find = true;
if(bubble.x > b.x){
vx = -vx;
}
if(bubble.y > b.y){
vy = -vy;
}
bubble.x += vx;
bubble.y += vy;
}
}
function Stalker(bubble, bubbles){
d = dist(bubble.x, bubble.y, myBubble.x, myBubble.y);
stalking(bubble, myBubble);
for(let i = 0; i < bubbles.length && !find; i++){
let b = bubbles[i];
if(bubble !== b){
d = dist(bubble.x, bubble.y, b.x, b.y);
stalking(bubble, b);
}else{
bubble.move();
}
}
}