xxxxxxxxxx
var bubbles_list = []
var burstcount = 0 ;
var timer
function setup() {
createCanvas(600, 600);
timer = setTimeout(check_if_win_or_lose, 3000);
for (var i =0;i<100; i++){
bubbles_list.push( new Bubbles());
}
}
function draw() {
background('pink');
for (var i =0; i<50 ; 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")
}
}
//Blueprint
class Bubbles{
//variable
// need to put constructor to make it a function
constructor(){
this.x = random(600);
this.y = random(600);
this.size = random(10,150);
this.bubble_color= color(random(0,90), random(4,90), random(60,89));
this.speed = random(-1, 4)
}
//functions
//display
display(){
noStroke()
fill(this.bubble_color);
circle(this.x, this.y, this.size);
}
//move
move(){
this.x +=this.speed;
if (this.x > 600){
this.speed= - this.speed;
}
if (this.x < 0){
this.speed = - this.speed;
}
}
//popthebubble
burst(){
if(dist(mouseX,mouseY,this.x,this.y) < this.size/2){
if(mouseIsPressed){
this.x = -100000000;
burstcount++;
print(burstcount);
}
}
}
}