// MingQing Peng - Midterm 

String title= "CST112 MIDTERM";
String author= "MingQing Peng";
String instructions= "q to quit; r to reset; ? for help";
String news= "hahaha~~lets go fishing";

//// GLOBAL DECLARATIONS ////

boolean day= true;
float surface;
float left, right, top, bottom;
float x, y, w, h, dx, dy;

float sunX, sunY, sunDX=1;
float boatX, boatY, boatDX=2, boatDY=0, boatW=100, boatH=20;
int boatCounter=0;

float fishX, fishY, fishDX=3, fishDY, fishW=60, fishH=20;
//boat goes back and forth. schools of fish swim



//// Setup:  size, reset, etc.
void setup() {
  size( 600,400 );
  background(200,250,250);
  surface=  height/4;
  // Set top,left, etc.
  top=  surface;
  rectMode(CENTER);
  
  reset();
}
//// reset:  initialize all values; randomize some. 
void reset() {
  // Starting positions
  x=  left+10;  y=top+50;
  dx=  3;  dy=0;
  day=true;
//fish  
  fishX=  0;
  fishY=  random(20,surface);
  fishDX=  random(1,10);
  fishDY= 0;
  fishW=  60 * random(0.5,3.0);
  fishH=  fishW/5;
}


////Next frame:  scene, boat, octopus, school
void draw() {
  scene();      // Sky and sea; day and night
  boat();       // Back & forth on surface (always pointing forward).
  octo();       // Rises slowly (8 legs waving), sinks quickly.
  school();     // Random number, each slightly smaller, behind, & below.
  messages();   // Text on screen:  title, author, etc. AND a "score"
}
//// EVENT HANDLERS:  mousePressed(), keyPressed()

void keyPressed() {
  if (key == 'q') exit();
  if (key == 'r') restart();
  if (key == 'd') day(); 
  if (key == 'n') night();
}
void mousePressed() {
    //// Click on boat to stop or start.
       // +++++ INSERT YOUR CODE HERE ++++

    //// Click on octopus to destroy it.
       // +++++ INSERT YOUR CODE HERE ++++

}
//// Check for hits.
boolean hit( float x, float y, float xx, float yy, float ww, float hh ) {
  // Return true if (x,y) is near (xx,yy)
 boolean result=false;
 if (x>xx && x<xx+ww && y<yy+hh){
   result= true;
 } else{
 result= false;
}
  return true;
}


//// scene:  sky, sun, ocean
void scene() {
  if (day) {
    background( 200,220,255 );      // sky is blue
    fill(255,255,0);                // sun is yellow
    ellipse( x, y, 40,40 );
  } else {
    background( 50,150,200 );      // night sky is dark blue
    fill(150,150,150);           // moon is whitish
    ellipse( x, y, 40,40 );
  }
  //Sun
  sunX += sunDX;
  sunY += sunDY;
  if (x> right-20){
    x= left+20;
    day= !day;
}
/** boat:  moves back and forth, across the surface.
  * Red hull points to direction of travel.
  * Boat stops while fishing.
*/
void boat() {
  if (boatX>right || boatX<left-aw ) boatDX = -boatDX;    // bouncing
  if (boatY>bottom-ah || boatY<top) boatDY = -boatDY;
  fill(255,0,0);
  rect(boatX, boatY, boatW, boatH);
}
////  octopus
void octo() {
  octo +=random(-20,20);
  fill(0,255,0);
  ellipse(x,y,60,60);
  rectMode(BOTTOM);
void eye( float x, float y, float d, float look ) {                  
  fill(255);
  ellipse( x,y, d*1.5,d );
  fill(0,0,255);
  ellipse( x+look*d/4,y, d/2,d/2 );
}
  
}

/**  school of fish:  smaller 7 smaller, behind & below.
*/
void school() {
  fishX += fishDX;
     float down=0;
  for (int j=0; j<n; j++ ) {
    fishDraw( fishx,fishy+down,fishw,fishh );
    fishx=  fishx - fishw -20;            // Behind
    down=  down + fishh;          // Lower
    fishw=  fishw * 0.8;
    fishh=  fishh * 0.8;
}
////Text on screen
void messages() {
  text( "MIDTERM", width/3, 20 );
  text( "MingQing Peng", 10, height-15 );
  text( "SCORE=  " + score,  width-200, 25 );
  
  help();
}
void help() {
  float x=width*2/3, y=bottom-100;
  fill(0);
  text( "q to quit; r to reset; ? for help", x, y );
  text( "Click octopus to remove it.", x, y+15 );
  text( "Click boat to catch fish", x, y+30 );
}