xxxxxxxxxx
68
var b;
var lose =0;
var startT = 0;
function setup() {
createCanvas(600, 600);
b = new ball(random(20, width-20),random(120, height-20));
}
function draw() {
background("pink");
noStroke();
updateBall(b);
textFont("cursive");
textAlign(CENTER);
textSize(40);
text("You could Break my Heart " + lose + " \n Times and I'd Still Love You", width/2, 50);
stroke("red");
strokeWeight(10);
line(mouseX-40, height-20, mouseX+40, height-20);
}
function ball(x,y) {
this.vx = random(-10,10);
this.vy = random(-10,10);
this.x = x;
this.y = y;
heart(this.x,this.y,40,40);
}
function updateBall(b){
b.x += b.vx;
b.y += b.vy;
if(b.x>=width-20 || b.x<=20){
b.vx *= -1;
}
if((b.y>=height-40 && mouseX-40 <= b.x && mouseX+40>=b.x) || b.y<=120){
b.vy *= -1;
} else if(b.y>height-40) {
lose++;
setup();
}
b = ball(b.x,b.y);
}
function heart(x, y, w, h){
fill("red");
noStroke();
for(var sign = -1; sign <= 1; sign+=2){
beginShape();
vertex(x, y-(h/3.5));
curveVertex(x, y-(h/3.5));
curveVertex(x+sign*(w/3.5), y-(h/2));
curveVertex(x+sign*(w/2), y-(h/2.5));
curveVertex(x+sign*(w/2), y-(h/8));
curveVertex(x+sign*(w/8), y+(h/4));
curveVertex(x, y+(h/2));
vertex(x, y+(h/2));
endShape();
}
}