xxxxxxxxxx
54
class Block {
constructor(x, y) {
this.x = x;
this.y = y;
this.angle = 0;
this.c = 70;
this.speed = 3;
}
display() {
noFill();
stroke(this.c);
push();
translate(this.x, this.y);
rotate(this.angle);
this.drawX();
pop();
}
move() {
let distance;
// If mouse is moving, check distance from mouse
if (abs(pmouseX - mouseX) != 0 || abs(pmouseY - mouseY) != 0) {
distance = dist(mouseX, mouseY, this.x, this.y);
if (distance < distMouse) {
this.angle += this.speed;
this.c = 255;
}
}
// If block is already rotating, check how much it has been rotated
if (this.angle > 0 && this.angle < 90) {
this.angle += this.speed;
if (this.c > 70) {
this.c -= 7;
}
} else {
this.angle = 0;
this.c = 70;
}
}
drawRect() {
rect(0, 0, size - offset, size - offset);
}
drawX() {
let margin = -size/2;
line(margin + offset/2, margin + offset/2, margin + size - offset/2, margin + size - offset/2);
line(margin + size - offset/2, margin + offset/2, margin + offset/2, margin + size - offset/2);
}
}