xxxxxxxxxx
34
class Fish {
constructor(x, y) {
this.pos = createVector(x,y);
this.vel = createVector(3,3);
this.speed = random(5, 10);
this.dim = 30;
}
newDir() {
this.vel = p5.Vector.random2D();
this.vel.mult(this.speed);
}
update() {
if(frameCount % 4 == 0) {
this.newDir();
}
this.pos = p5.Vector.lerp(this.pos, this.pos.add(this.vel), this.speed / 3);
}
checkCollide(other) {
return p5.Vector.dist(this.pos, other.pos) <= this.dim;
}
show() {
fill(0, 244, 0);
rectMode(CENTER);
rect(this.pos.x, this.pos.y, 20, 20);
noFill();
circle(this.pos.x, this.pos.y, this.dim);
}
}