xxxxxxxxxx
var bubbles_list = []
var burstcount = 0;
var timer;
function setup() {
createCanvas(400, 400);
for (var i = 0; i < 100; i++){
bubbles_list.push(new Bubbles());
}
timer = setTimeout(endscreen, 5000);
}
function draw() {
background(45, 64, 94);
bubble_1 = new Bubbles();
bubble_2 = new Bubbles();
for (var i = 0; i < 50 ; i++){
bubbles_list[i].display();
bubbles_list[i].move();
bubbles_list[i].burst();
}
}
function endscreen(){
if (burstcount > 4){
print ("winner!")
} else{
print ("try again")
}
}
//BLUEPRINT
class Bubbles {
constructor(){
this.x = random(400);
this.y = random(400);
this.size = random (30, 90);
this.c = color(random(0,100), random(0,100), random(100,255));
this.speed = random(-1.5, 1.5)
}
//functions
display(){
stroke(200, 200, 255);
fill(this.c);
circle(this.x, this.y, this.size);
}
move(){
this.x += this.speed;
if (this.x > 600){
this.speed = - this.speed;
}
if (this.x < 0){
this.speed = + this.speed;
}{
this.y += this.speed;
if (this.y > 600){
this.speed = - this.speed;
}
if (this.y < 0){
this.speed = + this.speed; }
}
}
//burst
burst(){
if(dist(mouseX, mouseY, this.x, this.y)< this.size/2){
if(mouseIsPressed){
this.x = - 1000000000;
burstcount ++;
print(burstcount);}
}
}
}