xxxxxxxxxx
58
var bx;
var by;
var diam;
var vx;
var vy;
var radius;
var score;
function setup() {
createCanvas(500, 500);
diam = 40;
radius = diam/2;
bx = radius;
by = 200;
score = 0;
vx = 6.0;
vy = 3.0;
}
function draw() {
rectMode(CENTER);
background(255, 200, 200);
let yc = constrain(mouseY, 0, height);
rect(450, yc, 12, 60);
fill(0);
ellipse(bx, by, diam, diam);
if (yc - 30 <= by && by <= yc + 30 && bx > 444 - radius && bx < 450 - radius) {
vx = -vx;
score++;
}
if (bx < radius) {
vx = -vx;
}
if (by < radius || by > height - radius) {
vy = -vy;
}
if (bx > width - radius) {
push();
textAlign(CENTER);
textSize(50);
text("GAME OVER", width/2, height/2);
pop();
}
textSize(24);
text("score: " + score, 10, 30);
bx = bx + vx;
by = by + vy;
}