Homework 3

Please complete this homework before next class. I will be posting the
solutions after next class.


Problem set A

Import the red Enemy dodging program and add as many of the following features as you can :
- Make it so that there is a score. Do this by having a integer score variable
that increases as the game goes on. Make it so that when the game is over,
the score is printed.
- Make it so that you can click to restart the game.
- Try making it so that the game starts off easy, and then gets harder.

Part B

For part B, you'll be writing a small game from scratch. Good luck :) !

The game will work like this :
You will control a circle. There will be green circles
all over the screen. The objective of the game will be collect the green circles to get points.

The first step will be to create a class that represents the "targets".
Targets are the green circles that your character will have to collect.
The class Target should have the following properties :
- positionX and positionY
- sizeX and sizeY

The next step will be get the code running that allows you to move a circle around the screen. This is available on the google doc.

Next, we should create an array of Targets. Look at code that we've written in the past for help.

We have to initialize all of the Targets in the array. What this means is
that currently the array is empty. You have to fill it with objects.
We can do that by using a loop to go through and create a new target for every slot in the array.
Refer to the red Enemy game for an example on how to do this.
We only need to do this once, so it should happen in the setup function.

Next we need to draw the Targets on the screen. In the draw function, write a
loop that goes through the Targets array and draws an ellipse for every target onto the screen.

Finally, we need to make it so that if the player is near any circle, the circle disappears.

To do this, first add a new variable to the Target class called "visible".
This variable should be a boolean. The variable will be true when the target is visible, and false when the target is gone.
"visible" should start off as true by default.

Next, make it so that each Target only gets drawn if its visible property
is set to true.
Ex :
if (targets[i].visible == true)

Finally, we need to set any target that is near our character to be invisible.
In the loop where we draw the character, check if the current Target is close to
character by using the distance function.
If the Target is, set its "visible" property to be false like so :
targets[i].visible = false;

If you have time, try adding in a score to the game!
Or make it so that targets spawn in randomly when you touch them.
Or make it so that there is a time limit.