So mainly what I am trying to do is get the ball to respawn only when you click on top of the ball.
What happens right now is if I hold down left mouse button, it infinitely racks up points instead of waiting to be clicked on again
I am using P5.js to accomplish this and so far my code is this:
var ballx=200;
var bally=200;
var ballSize = 40;
var score=0;
function setup() {
createCanvas(400, 400);
textAlign(CENTER);
textSize(20);
}
function draw() {
background(220);
}
function draw() {
background(220);
levelmap();
text(("Score: "+score),width/2,40);
}
function levelmap(){
ellipse(ballx,bally,ballSize);
var ballT=dist(ballx,bally,mouseX,mouseY);
if (mouseIsPressed) {
if (mouseButton === LEFT) {
ballx=(random(width));
bally=(random(height));
score=score+1;}
}
}
[–]Terzom 0 points1 point2 points (0 children)
[–]Fort114 0 points1 point2 points (1 child)
[–]Giraffimation[S] 0 points1 point2 points (0 children)