Exploding Targets

OK, before you get excited about exploding anything, all that happens is that targets (circles), when they are touched by the player's ball, fade out.  Sorry about the disappointment (jeez? seriously?)

You'll create the same type of game as we did yesterday, with a ball controlled by the player's WASD key hits, but the ball's maximum velocity in any direction (x or y) is limited by a global variable, "MaxVel".  Also, the ball is stopped at the borders (and its velocity drops to 0 there).

See the code template below. 

You'll create this program all in one file (your Target class will be in this file), so there's no issue about creating a folder to hold 2 files.

Here's a video of the game in action.

As you can see, when touched, the target turns red, and then fades to black slowly over a period of time controlled by ExplodingTime.

All of the state changing and color changing occurs in the Target's display() method.
 

int ntargets = 15;
Target[] targets = new Target[ntargets];
int TargetRadius = 20;
float ExplodingTime = 3;  // number of seconds of darkening rec color, then DEAD
int BallRadius = 15;
int MaxVel = 3;  // maximum velocity in + or - in x or y direction

// the target's states:
int ALIVE = 0;
int EXPLODING = 1;
int DEAD = 2;

// Player's ball parameters
int bx,by,bxvel,byvel;

void setup() {
   size(600,600);
   background(0);
   for(int i = 0; i < ntargets; ++i)
     targets[i] = new Target();
   bx = width/2;
   by = height/2;
   bxvel = 0;
   byvel = 0;
   stroke(255);  // white border around targets
}

void draw() {
  background(0);
  stroke(255);
  for (int i = 0; i < ntargets; ++i) {
    targets[i].display();
  }

  // move the player's ball
}

/* ===================
 keyPressed:
 Change the speeds of the player ball with keystrokes as follows
 But make sure that MaxVel is not exceeded in any direction
   'w' : y speed - 1
   'a' : x speed - 1
   's' : y speed + 1
   'd' : x speed + 1
 =================== */

void keyPressed() {
	// good code here
}


class Target {
  int cx, cy;
  int startedExploding;  // in milliseconds (use millis())
  int state;
  color c;
  
  Target() {
	// create it here
  }
  
  void display() {
	// all the heavy-duty code here
  }
}