CST122 test #1 & test #2

INSTRUCTIONS

Using the Processing language, create a "sketch" that meets requirements given below.
Run the sample program test12.jar to illustrate the behaviour specified for this sketch:
Sample code and declarations are provided below, as a starting point for your own code.

These instructions apply to two tests, which will be graded separately.

  1. test1 -- in class:
      Write your code in class, today, then upload it to your folder as test1yourname.txt
  2. test2 -- takehome:
      For the takehome" test, revise (or replace) your code, then upload it BEFORE the next class as test2yourname.txt
GRADING:


REQUIREMENTS & SPECIFICATIONS

The sketch consists of these componets: the scene, a shark, an octopus, and a school of several fish. Each component should be handled by a separate method, to allow modularization of your code. The draw() method consists only of calls to these 4 methods.


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.


SAMPLE CODE & DECLARATIONS

//// 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 ++++
  }
}