xxxxxxxxxx
53
class Object {
constructor(xPos, yPos, width, height) {
this.xPos = xPos;
this.yPos = yPos;
this.height = height;
this.width = width;
}
update() {
if (this.xPos <= mouseX + 10 && this.xPos >= mouseX - 10){
this.xPos -= 30;
}
if (this.yPos <= mouseY + 10 && this.yPos >= mouseY - 10){
this.yPos -= 30;
}
}
draw() {
fill(255, 0, 0);
ellipse(this.xPos, this.yPos, this.width, this.height);
console.log(this.xPos);
}
}
let objects = [];
function setup() {
createCanvas(windowWidth, windowHeight);
noStroke();
background(244);
for (let i = 0; i < 200; i++){
let randomSize = random(10, 20);
objects[i++] = new Object(
random(0, width),
random(0, height),
randomSize,
randomSize
);
}
}
function draw() {
for (let i = 0; i < 200; i++){
objects[i].update();
objects[i].draw();
}
console.log("hi");
}