These instructions apply to two tests, which will be graded separately.
scene: dark-green water, below a light-blue sky, with a yellow sun (and a score).
fish: A school of fish follows the leader fish across the screen. Leader fish (fishX,fishY) moves right and down (by 3 and 2 pixels, respectively). When the leader fish reaches the end (right side or bottom of screen), create a new school of fish with random values as follows:
fishMany= 2 + (int) random(6);
fishX= fishMany*fishSpacing; // Starting point for the leader.
fishY= surface+random(height/2);
fishWidth= 20+random(30); // Size of leader.
fishHeight= 0.75 * fishWidth;
fishRed= 150 + (int) random(100); // Fish redness.
octopus:
The octopus is a purple rectangle (80x120)
with eight (8) thick legs dangling beneath.
(Use a for loop to draw each leg as a line with stroke weight of 3).
Octopus follows mouse position.
When it gets close enough to the fish,
it "eats" one of them:
reduce fishMany by one (but not below zero),
and earn some score points.
EXTRA:
Make the octopus legs point toward the shark.
shark:
The shark (a grey rectangle)
moves very fast, toward the octopus.
On each frame, the shark computes the distance to the octopus,
and moves to cover 10% of that distance
in both X and Y.
For example, if the octopus is at (500,200) and the shark is at (100,400),
the shark will move +40 in X and -20 in Y.
(On the next frame, the shark moves only +36 in X, then +32, then +30, etc.)
If the shark comes close enough, he eats the octopus!
Move shark to lower-right corner when this happens.
EXTRA:
When the octopus gets eaten,
deduct 100 points, make background black (just for this one frame);
EXTRA:
The player may also click the mouse to move shark to lower-right corner,
losing only 50 points.
//// Test #1 -- Sample code.
float sunX=300, sunY=50;
float surface=100;
int fishMany=6; // How many fish.
int fishRed= 200; // Red color level for fish.
float fishSpacing=50;
float fishX=0, fishY=surface+100;
float fishWidth=60, fishHeight=45;
float sharkX=100, sharkY=360;
float octoX=500, octoY=200;
int score=0;
void setup() //// setup
{
size(800,600);
}
void draw() //// Next frame.
{
scene();
fish(); //// school of fish swim to the right.
shark(); //// Shark chases fish.
octopus(); //// Octopus -- 8 arms point toward shark.
}
void scene() //// waves on surface, rocks at bottom.
{
background( 200,200,255 ); // (Sky)
//// Sun. //// ++++ ADD YOUR CODE HERE ++++
//// Water //// ++++ ADD YOUR CODE HERE ++++
//// Waves on the surface. //// ++++ ADD YOUR CODE HERE ++++
}
void fish() //// school of fish.
{
if (fishX>width || fishY>height || fishMany<1) // Check if done. Reset fish on left.
{
fishMany= 2 + (int) random(6);
fishX= fishMany*fishSpacing; // Starting point for the leader.
fishY= surface+random(height/2);
fishWidth= 20+random(30); // Size of leader.
fishHeight= 0.75 * fishWidth;
fishRed= 150 + (int) random(100); // Fish redness.
}
//// Move school of fish: 3 left, 2 down. //// ++++ ADD YOUR CODE HERE ++++
//// Draw each fish - size gets smaller //// ++++ ADD YOUR CODE HERE ++++
}
void octopus() //// Octopus with 8 legs pointing toward shark.
{
octoX=mouseX;
octoY=mouseY;
//// Draw octopus, add 8 legs. //// ++++ ADD YOUR CODE HERE ++++
}
void shark() //// Shark chases octopus.
{
//// Move shark. //// ++++ ADD YOUR CODE HERE ++++
//// Draw shark. //// ++++ ADD YOUR CODE HERE ++++
//// Shark catches Octopus.
if (dist(sharkX,sharkY,octoX,octoY) < 50)
{
//// ++++ YOUR CODE GOES HERE ++++
}
}
|