xxxxxxxxxx
49
class Mover {
constructor() {
this.position = createVector(random(width), random(height));
this.velocity = createVector(0, 0);
this.acceleration = createVector(-.6, 0.6);
this.topSpeed = 10;
this.friction = 0.95;
}
update() {
if (keyIsDown(UP_ARROW) === true) {
this.velocity.y -= this.acceleration.y;
} else if (keyIsDown(DOWN_ARROW) === true) {
this.velocity.y += this.acceleration.y;
}
if (keyIsDown(RIGHT_ARROW) === true) {
this.velocity.x -= this.acceleration.x;
} else if (keyIsDown(LEFT_ARROW) === true) {
this.velocity.x += this.acceleration.x;
}
this.velocity.limit(this.topSpeed);
this.position.add(this.velocity);
// this.velocity.mult(this.friction);
}
show() {
noStroke();
fill(220);
circle(this.position.x, this.position.y, 50);
}
checkEdges() {
if (this.position.x < 0) {
this.position.x = width;
} else if (this.position.x > width) {
this.position.x = 0;
}
if (this.position.y < 0) {
this.position.y = height;
} else if (this.position.y > height) {
this.position.y = 0;
}
}
}