xxxxxxxxxx
var bubble1, bubble2, bubble3;
var burstCount = 0;
var timer;
var bubbleList = []
function setup() {
createCanvas(400, 400);
bubble1 = new Bubbles();
bubble2 = new Bubbles();
//timer = setTimeout(checkIfWinOrLose, 5000);
for(var j = 0; j < 100; j++){
bubbleList.push(new Bubbles())
}
}
function draw() {
background(0);
for(var i = 0; i < 100; i++){
bubbleList[i].display()
bubbleList[i].move()
bubbleList[i].burst()
}
}
// function checkIfWinOrLose() {
// if (burstCount == 2) {
// print("You Won");
// }
// else {
// print("You Lost");
// }
// }
class Bubbles {
//"constructs" our variables
constructor() {
this.x = random(400);
this.y = random(400);
this.s = random(50, 80);
this.c = color(245, random(18,230), random(233,251));
this.speed = random(-1,1)
}
display() {
fill(this.c);
noStroke();
circle(this.x, this.y, this.s);
}
move(){
this.x+= this.speed
if (this.x > 400){
this.speed = -this.speed
}
if (this.x < 0){
this.speed = -this.speed
}
}
burst() {
if (dist(mouseX, mouseY, this.x, this.y) < this.s / 2) {
if (mouseIsPressed) {
this.x = -10000;
burstCount++;
//print(burstCount);
}
}
}
}