xxxxxxxxxx
50
class Vehicle {
constructor(location = createVector(random(width), random(height))) {
this.location = location;
this.velocity = createVector(0, 0);
this.acceleration = createVector(0, 0);
this.maxSpeed = 5;
this.maxForce = 1;
this.mass = 1;
}
seek(target) {
let v = p5.Vector.sub(target, this.location);
v.normalize();
v.mult(this.maxSpeed);
this.applyForce(p5.Vector.sub(v, this.velocity).limit(this.maxForce));
}
act() {
this.seek(createVector(mouseX, mouseY));
this.update();
this.draw();
}
update() {
this.velocity.add(this.acceleration);
this.location.add(this.velocity);
this.acceleration.mult(0);
}
applyForce(force) {
this.acceleration.add(p5.Vector.div(force, this.mass));
}
draw() {
if( abs(degrees(this.velocity.heading())) > 90 ) {
push();
translate(this.location.x+50, this.location.y+50);
rotate(radians(degrees(this.velocity.heading())+45));
image(birdthree, 0, 0, 100, 100);
pop();
} else {
push();
translate(this.location.x+50, this.location.y+50);
rotate(radians(degrees(this.velocity.heading())-45));
image(birdthree, 0, 0, 100, 100);
pop();
}
}
}