xxxxxxxxxx
38
let vx = 5;
let vy=1.5;
let ballx=15;
let bally = 300;
let score = 0;
function setup() {
createCanvas(600, 600);
}
function draw() {
background(220, 220, 220, 40);
noStroke();
fill(0);
ellipse(ballx, bally, 30, 30);
ballx += vx;
bally += vy;
rectMode(RADIUS);
rectW = 10;
rx = width*0.75
ry = mouseY
rect(rx, ry, rectW, 50);
text("score:" + score, width/2, 30);
if ((ballx-10) < 0){
vx *= -1;
} if ((ballx+10 )>width) {
vx *= -1;
} if ((bally-10) < 0 || (bally+10) > height){
vy *= -1;
} if ((ballx+10 == rx-(rectW/2)) && (bally-10 < ry+25) && (bally+10 >ry-25) && (vx>0)){
vx *= -1;
score++;
}
}