In this assignment, you will add text to the game from a previous assignment that lets the player “pop” balloons by moving the mouse over them. This sketch will be named textgame.
final int in the Balloon class to
specify the height of the playing area. You can’t use
height, because that includes the text area.millis()
function to figure out how long
the program has been running.noLoop() so
that Processing will not call draw() any more.startGame()
that creates the balloons, sets the timing variables, and
calls the loop() function to
make Processing start executing the draw() function
again.You can’t just say something like this:
int minutes = some calculation; int seconds = some calculation; String elapsedTime = minutes + ":" + seconds;
because, if the seconds is less than 10, you would end up with a string like
2:5 instead of 2:05. Here is a function
named twoDigits() which takes an integer as a parameter and
returns a two-digit string (as a String), and how you
might use it in your program.
String twoDigits(int n)
{
String result = "" + n; // converts integer to String
if (n < 10)
{
result = "0" + result;
}
return result;
}
// how you use it:
int minutes = some calculation;
int seconds = some calculation;
String elapsedTime = minutes + ":"
+ twoDigits(seconds);
Zip up the sketch into a zip file named
textgame.zip and upload it.