Whack-A-Mole Game

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 objects (balls or buttons) in a class or with your example.

boolean b = false;

void setup()
  {
  size(700, 700);
  x = width/2;
  y = height/2;
  ttl = 2;
  noStroke();
  }

void draw()
  {
  background(255);

  if (frameCount%(3*60) == 0)                      //Every 3s
    {
    ttl =  frameCount + int(random(0.5*60, 2*60)); //random ttl .5 to 2 s
    b = true;
    } 

  if (b == true)
    {  
    fill(100);
    circle(x, y, 200);
    }
  
  if (frameCount > ttl) 
    {
    b = false;
    }
  }

References:

I do not support or endorse the whacking of moles. :)

:)

4 Likes