Urgently need help on finishing my project its called the dropping ball game and everytime the ball drops you would click on it and the score would go up by 1 and vice versa but having a hard time clicking on the ellipse. This what I got so far if someone could help that would be awsome.
type or paste code here
PImage p;
int missed = 0;
int hits = 0;
int score = 0;
int y = 25;
int x = (int)random(25,475);
void setup(){
p = loadImage("projectBackground.png");
size(500,700);
background(255);
}
void draw(){
background(p);
fill(#DFF218);
ellipse(x,y,50,50);
y+=5;
if(y >= height){
y = 25;
x = (int)random(25,475);}
fill(0);
textSize(25);
textAlign(CENTER);
text("Score= " + score, 100,650);
text("Missed= " + missed, 250,650);
text("Hits= " + hits, 400,650);
if(y > 575){
y = 25;
x = (int)random(25,475);
}
}
void mouseClicked(){
if(mouseX < 600 && mouseX > 0 && mouseY > 0 && mouseY < 500){
hits++;
}
}
void keyPressed(){
if(key == 'r'){
loop();
}
if(key == 's'){
noLoop();
}
}
The problem is that when mouseClicked() runs, you check if the mouse’s position is in a rectangle that takes up most of the screen. What you really need to do is see if the click is close enough to the center of the circle so that the click was on the circle. That is, the distance between where the click was and where the center of the circle is needs to be less than the radius of the circle.
You can use dist() to get the distance between two points. One point is (mouseX, mouseY), the other is (x,y), the center of the circle.
How big is your circle? So what’s it’s radius?
Well, you’d have to adjust the circle’s position when it’s clicked… You know when a click occurs because you’re increasing the hits counter… Just give it a new position then.