Lab 09 - Falling Shapes
Assignment
-
Create a new
GraphicsProgram
withinit
andrun
methods. Create an empty game loop inrun
. -
Create an ArrayList of GObjects. The ArrayList should be a class variable, and should be initialized in the
init
method. -
Write the necessary code so that when the user types a key on the keyboard, a new shape is created and added to the ArrayList. If the user presses "c", it should create a circle, "s" a square, "r" a rectangle.
-
The location, color, and size of the shape should be random.
-
When a shape is created, it should be added to the ArrayList.
-
After you get steps 1 - 5 working, modify the
run()
method so that every frame, each object in the ArrayList is moved down the canvas by a certain number of pixels.
BONUS:
Opportunities for bonus points include:
-
Making the shapes rotate at random rates as they fall.
-
Removing the shapes from the ArrayList once they pass below the bottom edge of the window.
Hints
-
Refer back to the Spaceship code to remember how the run loop and keyboard handling is done.
-
Refer back to assignment 06 for how to get a random number in a certain range.
Submission
To submit your assignment, follow the instructions for code submission. Make sure you submit your entire project so that both Java files are included.