Use the arrow keys to move him out of the way, click the bubbles with your mouse to win!
xxxxxxxxxx
var bubbles_list = []
var burstcount = 0
var timer//not class
var x = 200
var y = 200
function setup() {
createCanvas(400, 400);
for(var i =0; i<50; i++){
bubbles_list.push(new Bubbles())
}
timer = setTimeout(check_if_win_or_lose,7000)
}
function draw() {
background(231, 111, 81);
for (var i=0; i<50; i++){
bubbles_list[i].display()
bubbles_list[i].burst()
noStroke() // bubble man
fill(247, 37, 133);
ellipse(x,y,400,400);
noStroke()
fill (255, 189, 0)
circle (x-80, y-20, 100)
noStroke()
fill (255, 189, 0)
circle (x+90, y-20, 100)
}
if (x >= 400){
x = 0;
}
}
//moving bubble man
function keyPressed() {
if (keyCode === UP_ARROW) {
y = y - 10;
} else if (keyCode === DOWN_ARROW) {
y = y + 10;
}
if (keyCode === LEFT_ARROW) {
x = x - 5;
} else if (keyCode === RIGHT_ARROW) {
x = x + 5;
}
}//win or lose
function check_if_win_or_lose(){
if (burstcount == 5){
print("yay you won!")
} else{
print("you lost. you're a failure.")
}
}
class Bubbles {//class not var
constructor(){
this.x = random(400);
this.y = random(400);
this.s = random(50,100);
this.c = color(random(100), random(200),random(200))
}
//display
display(){
fill(this.c)
circle (this.x,this.y,this.s)
}
//burst bubbles
burst(){
if(dist(x,y,this.x,this.y) < this.s/2){
if(mouseIsPressed){
this.x = -100
burstcount++
print(burstcount)
}
}
}
}