xxxxxxxxxx
50
class Mover {
constructor() {
this.acceleration = createVector(0, 0);
this.position = createVector(width / 10, height / 2);
this.velocity = createVector(0, 0);
this.mass=1;
}
applyForce(force) {
force.div(this.mass);
this.acceleration.add(force); //assuming mass=1
}
update() {
this.position.add(this.velocity);
this.velocity.add(this.acceleration);
this.acceleration.set(0, 0); //needs to be at the end of the "update"
}
display() {
stroke(116, 238, 21);
strokeWeight(4);
fill(0, 102, 203);
ellipse(this.position.x, this.position.y, 50, 50);
}
edges() {
// checking the edges to make sure the ball doesn't go off screen
if (this.position.y >= height) {
this.position.y = height;
this.velocity.y *= -1;
}
if (this.position.x >= width) {
this.position.x = width;
this.velocity.x *= -1;
}
if (this.position.x <= 0){
this.position.x=0;
this.velocity.x *= -1;
}
if (this.position.y <= 0){
this.position.y=0;
this.velocity.y *= -1;
}
}
}