30 lines
773 B
JavaScript
30 lines
773 B
JavaScript
class GreenOrb {
|
|
constructor() {
|
|
this.pos = createVector(random(width), random(height));
|
|
this.r = 10;
|
|
this.vel = p5.Vector.random2D();
|
|
this.vel.mult(random(1, 2));
|
|
while (dist(this.pos.x, this.pos.y, ship.pos.x, ship.pos.y) < 100) {
|
|
this.pos = createVector(random(width), random(height));
|
|
}
|
|
}
|
|
|
|
update() {
|
|
this.pos.add(this.vel);
|
|
}
|
|
|
|
edges() {
|
|
if (this.pos.x > width + this.r) this.pos.x = -this.r;
|
|
else if (this.pos.x < -this.r) this.pos.x = width + this.r;
|
|
if (this.pos.y > height + this.r) this.pos.y = -this.r;
|
|
else if (this.pos.y < -this.r) this.pos.y = height + this.r;
|
|
}
|
|
|
|
show() {
|
|
push();
|
|
fill(0, 255, 0); // Green
|
|
noStroke();
|
|
ellipse(this.pos.x, this.pos.y, this.r * 2);
|
|
pop();
|
|
}
|
|
} |