xxxxxxxxxx
55
var px=300;
var py=300;
var diameter = 50;
var vx = 5;
var vy = 2;
var score = 0;
function setup() {
createCanvas(600, 600);
var score = 0;
}
function draw() {
background(100,100,255,50);
strokeWeight(0);
px = px + vx;
py = py + vy;
ellipse(px, py, 50, 50);
var radius = diameter / 2;
if (px > (width - radius)) {
vx = 0-vx;
}
if (py > (height - radius)) {
vy = 0-vy;
}
if (px < radius) {
vx = 0-vx;
}
if (py < radius) {
vy = 0-vy;
}
textSize(24);
text("score: " + score, width/2-50, height/2);
noStroke();
fill(255);
if (mouseY < 500){
rect(560,mouseY, 30, 100);
}
else{
rect(560,500, 30, 100);
}
if (((px +25 >= 560) && (py+25 >= mouseY))){
vx = (vx + 0.5)*-1;
vy = (vy +0.2)*-1;
score = score + 1;
}
}