xxxxxxxxxx
47
class Sheep {
constructor(x, y) {
this.pos = createVector(x, y);
this.size = 20;
this.active = false;
}
move() {
this.prevX = this.x;
this.prevY = this.y;
if (
mouseX > this.pos.x - this.size / 2 &&
mouseY > this.pos.y - this.size / 2 &&
mouseX < this.pos.x + this.size / 2 &&
mouseY < this.pos.y + this.size / 2
) {
this.active = true;
} else {
this.active = false;
}
function mouseDragged() {
if (this.active === true) {
this.pos.x = mouseX;
this.pos.y = mouseY;
}
}
console.log(this.active);
this.show();
}
show() {
rectMode(CENTER);
rect(this.pos.x, this.pos.y, this.size);
}
}
let newSheep;
function setup() {
createCanvas(400, 400);
newSheep = new Sheep(20, 20);
newSheep.show();
}
function draw() {
background(220);
newSheep.move();
}