Whack-a-mole Game - Slowing down draw
in
Programming Questions
•
1 year ago
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) {
- score += 1;
- }
- }
1