In this assignment, you will create a game that lets the player “pop” balloons by moving the mouse over them.
BalloonYou do not need to add any further instance variables. You already have all the ones you need (center x and y, width and height, color, and x- and y-speed).
Add the following methods to the Balloon class:
void draw()boolean hit(int pX, int pY)true if the point (pX, pY)
is inside the balloon, false otherwise. This requires a bit of
math, so I am giving you the code:
boolean hit(int pX, int pY)
{
float a = w / 2.0;
float b = h / 2.0;
float ex = pX - x; // calculate relative to center of ellipse
float ey = pY - y;
float r = (ex * ex) / (a * a) + (ey * ey) / (b * b);
return (r < 1);
}void pop()
Your main program makes a sketch that is 400 by 400 dots,
and sets the frame rate to 20.
The program will create an array of 30 Balloon objects of
different sizes and colors and speeds. For each balloon:
Your draw() function will have a loop that does the following
for each of the balloons in the array:
Zip up the sketch into a zip file named
game.zip and upload it.