xxxxxxxxxx
37
class spaceshipParts {
constructor(x, y) {
this.x = x;
this.y = y;
this.speed = speed;
this.xRspeed = random(-2, 1);
this.yRspeed = random(-2, 1);
this.size = random(20, 80);
this.col = color(26.09, 0, random(0, 45));
}
show() {
fill(this.col);
push()
translate(this.x, this.y);
rect(0, 0, this.size, this.size);
pop()
}
move() {
this.x += this.xRspeed;
this.y += this.yRspeed;
if (this.x < 0 || this.x > width) {
this.xRspeed = -this.xRspeed;
this.x += this.xRspeed;
}
if (this.y < 0 || this.y > height) {
this.yRspeed = -this.yRspeed;
this.y += this.yRspeed;
}
}
}