CST 112 Project #5
"Dog Race"
using Arrays of Objects
-
Write your own (Processing) Java code
to follow the instructions below,
-
Your completed code should be submitted
by noon, Saturday, Nov. 30,
in a file named "p5.pde" in your folder
on the website.
-
You may use any of your own code from previous projects and tests,
but be sure you understand all of the code you submit.
I N S T R U C T I O N S
Rewrite your code from Project #4 & Exam #4
(p4.pde & t4.pde),
using arrays for multiple objects,
and add the additional features described below.
Your declarations should look something like this:
// Declare arrays of objects: //
int nb=7, nd=4, nv=nd-1;
Button[] b= new Button[nb];
Dog[] d = new Dog[nd];
Varmit[] v = new Varmit[nv];
Bird blue;
String[] names = { "Rex", "Spot", "Mutt", "Lassie", "ALL" };
Note that the above code only constructs the arrays;
you must also
construct each instance of the objects,
with some initialization statemements like these:
//// Initialize the objects //
float yDog=yTracks;
for (int j=0; j<nd; ++j ) {
d[j] = new Dog( names[j], start, yDog );
yDog = yDog + 100;
}
blue = new Bird();
Additional features for Project #5:
(p5.pde):
- Add a fourth dog (and track), with another button for it.
Make the screen larger: size( 800, 600 );
- Click the mouse near any dog
to move that dog back several pixels.
Required features from Test #4
(t4.pde):
Blue bird flies slowly, back & forth, above horizon.
Grass along horizon:
green blades 20 pixels apart.
Small red triangles every 100 pixels,
along the bottom,
from start to finish,
Within each track, draw a red line & text
every 100 pixels:
to indicate distance:
100, 200, 300, 400, etc.
As dogs race,
draw a red circle around the leading dog.
// You may use code like this, to draw the red circle:
stroke(255,0,0);
color( 0,0,0, 255 ); // Transparent fill.
ellipse( x, y, 50, 50 );
stroke(0); // Restore defaults.
|
Click the mouse near any dog
to move that dog back.
Add a button to drop a brown "bomb" from the blue bird.
If bomb gets near any dog,
send that dog back to the starting line!
Required features from Project #4
(p4.pde):
- Racetrack:
- A racetrack with three parallel tracks (horizontally).
- Dogs:
In each track, a Dog
moves
(a random amount)
whenever its button is clicked.
-
Each dog should be a different color,
and drawn with at least three shapes..
- Buttons:
Four buttons are used to make the dogs move:
- Three buttons have the name of a dog,
and are the same color as that dog.
The fourth button moves ALL three dogs.
- Varmits:
After the race begins, two small varmits
-
run back and forth between the tracks
(bouncing off the ends).
- Messages
- The title and author are displayed on the screen:
When a dog crosses the finish line, the winner's name is displayed.
- Animation:
- Dogs and varmits should all display some sort of animation, as they move.