So I'm in a Computer Science course and we are coding a whack a mole game. The goal is to have the "mole" (in this case a circle) appear in a random place on the screen, stay there briefly, and then leave. By implementing the mouseClicked method, we then want to use if methods to change the score display on the bottom of the screen when the user clicks the circle. Unfortunately, processing always executes the draw statement before anything else, so it is impossible to simply slow the frame rate to make the game playable. So my question is, how else can I get the circle to stay put, in the simplest way possible? I've tried a variety of things already, but I'm very new to processing and coding in general. Can anyone help?
CODE:
int score;
float x, y;
final int EASY = 300;
final int NRML = 200;
final int HARD = 100;
float diameter = 25;
int height = NRML; //Plug in one of the constants to set
int width = NRML; //a difficulty level.
void setup() {
size(width, height);
background(255);
smooth();
textFont( loadFont("Arial.vlw") );
}
void draw() {
background(255);
fill(255, 155, 0);
x = random(0 + diameter, width - diameter);
y = random(0 + diameter, height - diameter);
ellipse(x, y, diameter, diameter);
x = x;
y = y;
ellipse(x, y, diameter, diameter);
if(score == 1) {
text("Score = 1", 10, NRML - 10);
} else if(score == 2) {
text("Score = 2", 10, NRML - 10);
} else if(score == 3) {
text("Score = 3", 10, NRML - 10);
} else if(score == 4) {
text("Score = 4", 10, NRML - 10);
} else if(score == 5) {
text("Score = 5", 10, NRML - 10);
} else if(score == 6) {
text("Score = 6", 10, NRML - 10);
} else if(score == 7) {
text("Score = 7", 10, NRML - 10);
} else if(score == 8) {
text("Score = 8", 10, NRML - 10);
} else if(score == 9) {
text("Score = 9", 10, NRML - 10);
} else if(score >= 10) {
text("You Win!!", 10, NRML - 10);
} else {
text("Score = 0", 10, NRML - 10);
}
}
void mouseClicked() {
if (x - diameter * .5 <= mouseX && mouseX <= x + diameter * .5 &&
y - diameter * .5 <= mouseY && mouseY <= y + diameter * .5) {
I'm having a little bit of trouble getting the mouseClicked method to loop. I'm trying to get an animation that displays a ball falling through the air due to gravity. Wherever the mouse is clicked the ball should appear and then fall from normal there. Unfortunately, the mouseClicked just starts the animation, but only continues to increment the ballY and deltaY if the mouse is clicked subsequently rather than automatically starting an animation. Because ballY is reset with every click, the result leaves nothing happening, and instead simply places the ball to the location of the click. Can anyone help? Here's the code: