I am a beginner to p5.js and I was trying to make a catching game, where the balls fall from the sky and you catch them with a basket, but when you run the code, sometimes the balls don't fall down until waiting a few seconds and moving the basket around, could anyone tell me why this is?
Here is my code:
let speed = 3;
let x = 300;
let y = 0;
let score = 0;
function setup() {
createCanvas(600, 400);
}
function draw() {
background(0);
ellipse(x, y, 20, 20);
y = y + speed;
rect(mouseX, height - 10, 60, 40);
fill(255);
text("score = " + score, 30, 20);
if (y > height - 10 && x > mouseX - 20 && x < mouseX + 20) {
y = -20;
speed += 1;
score += 1;
}
if (y == -20) {
x = random(width);
}
}
function reset(){
score = 0;
speed = 2;
y = -20;
}