xxxxxxxxxx
var bubble_1;
var bubble_2;
var bubbles_list = [];
var burstcount = 0;
var timer;
function setup() {
createCanvas(400, 400);
for(var i = 0; i < 10; i ++){
bubbles_list.push(new Bubbles());
}
print(bubbles_list);
timer = setTimeout(check_if_win_or_lose, 5000);
}
function draw() {
background(230,230,250);
for(var i =0; i< 10; i++){
bubbles_list[i].display();
bubbles_list[i].move();
bubbles_list[i].burst();
}
}
function check_if_win_or_lose(){
if(burstcount >= 2){
print("you won")
} else {
print("you lost")
}
}
class Bubbles{
constructor(){
this.x = random(800);
this.y = random(800);
this.s = random(50, 100);
this.c = color(204, 204, 255);
this.speed = random(-1, 1);
}
display(){
fill(this.c);
circle(this.x,this.y,this.s);
}
move(){
if(this.x > -10){
this.x+=this.speed;
if(this.x> 800){
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 = -100000000;
burstcount++;
print(burstcount);
}
}
}
}