Files
retro-asteroids/shieldOrb.js
2025-06-25 22:14:38 -05:00

30 lines
775 B
JavaScript

class ShieldOrb {
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, 255); // Cyan
noStroke();
ellipse(this.pos.x, this.pos.y, this.r * 2);
pop();
}
}