# Modifying a game: score, random, display

**URL:** <https://discourse.processing.org/t/modifying-a-game-score-random-display/22785>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [July 22, 2020, 8:41pm UTC](https://discourse.processing.org/t/modifying-a-game-score-random-display/22785 "2020-07-22T20:41:48Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![greenArtist7](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@greenArtist7](https://discourse.processing.org/u/greenArtist7)\
**Post date:** [July 24, 2020, 4:40pm UTC](https://discourse.processing.org/t/modifying-a-game-score-random-display/22785/21 "2020-07-24T16:40:34Z")

</div>

I’m trying to use the concept you suggested, and I don’t think I’m implementing it correctly. Below is the “test” code I put together. Once I put my mouse on the ellipse, it turns gray, but when I remove my mouse, it is still gray. How can I correct it to where it only turns gray if the mouse is on top?  
Also, when I try to add a virus2, neither one will popup anymore.

```auto
float x;
float y;
float r;
boolean virus1 = false;

void setup() {
  size (500, 500);
  x = 59;
  y = 59;
  r = 55;
}

void draw() {
  background(0);

  if (virus1 == true) {
    ellipse(x, y, r, r);
    if (dist(mouseX, mouseY, x, y) < r) {
      fill(150);
    }
  }
}

void keyPressed() {
  if (key == 'q') {
    virus1 = true;
  } else {
    virus1 = false;
  }
}

```

---

<div class="post-metadata">

**Author:** ![greenArtist7](https://avatars.discourse-cdn.com/v4/letter/g/9de0a6/32.png) [@greenArtist7](https://discourse.processing.org/u/greenArtist7)\
**Post date:** [July 24, 2020, 5:12pm UTC](https://discourse.processing.org/t/modifying-a-game-score-random-display/22785/22 "2020-07-24T17:12:53Z")

</div>

Thank you for confirming that all of the things I want to do are possible, and for trying to help me figure out how to make them possible. That’s the part I’m having trouble with 😅 implementing and adapting the information to what I want to do.

I will check out the mousePressed() function and try to use that instead of what I have. The score adds up way to fast that way! haha

As far as the array for the object. I thought about doing that initially, but I wasn’t sure how to implement it (while minimizing/simplifying the code) since I am using a certain key to activate each virus individually. (i.e. ‘w’ = virus1, ‘q’ = virus2). I tried googling it but I couldn’t find anything on this… that may be because I’m not searching properly, but I’m not sure how to search for that. Do you know of anything I can reference for further explanation?

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 24, 2020, 7:06pm UTC](https://discourse.processing.org/t/modifying-a-game-score-random-display/22785/23 "2020-07-24T19:06:13Z")

</div>

Hello,

In your recent example…

> [@greenArtist7](#):
>
> Once I put my mouse on the ellipse, it turns gray, but when I remove my mouse, it is still gray.

That is exactly what you programmed; you set fill(150) and that will remain so until you change it. You have not set it to any other value in your code.

> [@greenArtist7](#):
>
> when I try to add a virus2, neither one will popup anymore.

If you hit any key other than **‘q’** it will set **virus1 = false** as per your **if else statement**.

I suggest that you review your **if else statements** so you have a better understanding of how these work.

What condition do you want to set **virus1 = false**?  
When that condition is met then set **virus1 = false**.

You can use println() statements in your code to follow the state of variables to help with understanding flow and debugging.

The last two variables of ellipse are width and height and not radius.  
Take a look at the references for this.

`:)`

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 8, 2020, 10:55pm UTC](https://discourse.processing.org/t/modifying-a-game-score-random-display/22785/24 "2020-08-08T22:55:28Z")

</div>

I had actually started with your code and rewrote most of it for a personal challenge.

Here is an example of “time to live” for one button:

> [@Whack-A-Mole Game](https://discourse.processing.org/t/whack-a-mole-game/23113/8):
>
> Hello, I wrote an example that used an array of objects (balls) filling the canvas with different colors, radii, random locations and random time to live in a class to create these objects. I added the time to live last once everything else was working. There is a learning curve to doing this but worth it and can easily be updated. This is a very minimal example implementing “time to live” for one ball without a class. You can try to integrate it (or something similar) into an array of objec…

`:)`

[Previous page](https://discourse.processing.org/t/modifying-a-game-score-random-display/22785.md?page=1)
