///Cst112 midtem kelly Hernandez
///variables been declared globally
String title = "Under the Sea";
float xFish=500;
float yFish=300;
float xBoat=200;
float yBoat=110;
float dxBoat=1;
float xMoveboat= 30;
float xRightboat=90;
float xCrawl=665;
float yCrawl=565;

int boatscore=0;
float dxFish=random(2, 5);            ///speed at random not been declared global
float dyFish=random(-3, 3); 
float horizon;
float xDvfish= -100;
float xSvfish=-80;
float xDveye=50;
float eyeR;
float eyeG;
float eyeB;
float surface=  height/4;
int crawlscore=0;
int tunascore=0;
float R;
float B;
///SET UP//
void setup() {
  yFish=random(height/4, 600);      //sets up random position for fish
  xFish=random(0, 800);          /// random speed apply to x and y
      
  size(800, 600);
  horizon= height/2;
}

void draw () {

  background(200, 220, 250);
  fill(31, 120, 4);
  noStroke();
  rect(0, height/4, width, height*3/4);    //draw horizom at a quarter
  
  fish();
  boat();
  bounceboat();
  movefish();
  boatfishes();
  crawler();
  crawkey();
  crawfishes();
  message();
  
  
  
}

void scene()
{
}
void fish() {
  eyeR = random(0,180);
  eyeG = random(0,180);
  eyeB = random(0,180);
  fill(247, 180, 244);
  noStroke();
  ellipse(xFish, yFish, 160, 50 );// body fish
  triangle(xFish-20, yFish-23, xFish+10, yFish-23, xFish-5, yFish-50);     /// fin
  triangle(xFish+xSvfish, yFish, xFish+xDvfish, yFish-20, xFish+xDvfish, yFish+25);    ///tail
  fill(255);
  ellipse(xFish+xDveye, yFish-15, 10, 10);  //eye
  fill(eyeR,eyeG,eyeB);
  ellipse(xFish+xDveye, yFish-15, 5, 5);          //pupil
  fill(0);
  arc(xFish+xDveye, yFish, 10, 10, 0, PI+QUARTER_PI, CHORD);      //fish mouth in an arch
  fill(0);
  text( tunascore, xFish-10, yFish-5);
  text("BUBA", xFish-15, yFish+15);
} 
void movefish() {  
  xFish=xFish+ dxFish;    //new fish +old fish // changing the position betweeen them points
  yFish=yFish+ dyFish; 

  if (xFish<0) {        //bounces fish back from the x axis at ;ess than 0
    dxFish=1;
    xDvfish=-100;
   xSvfish=-80;
   xDveye=50;
   
  }
  if (xFish > width) {    //makes the fish move though the x axis
      dxFish=-1;          // bounces off at this speed
    xDvfish=100;
   xSvfish=80; 
   xDveye=-50;
}
  if (yFish<height/4) {      //horizon of the y axis movement
    dyFish=1;
  }
  if (yFish>height) {      //off the ground with heigtg
    dyFish=-1;               
  }
}



//boat distance from the fish
void boatfishes() 
{
      if(keyPressed){    
    if ( (key == 'b' && dist(xFish,yFish, surface-20,yBoat) <20));
                  //is less than the fish
      xFish= random(0,width);
      yFish= random (horizon, height);
      boatscore= boatscore+1;
    
  }
}

//comparison

void boat() { //show the boat
  noStroke();
  fill(255, 0, 0);
  rect(xBoat, yBoat, 90, 40);        //bodyy
  triangle(xBoat+xMoveboat+xRightboat, yBoat, xBoat+xRightboat, yBoat, xBoat+xRightboat, yBoat+40);/// pointy nose
  rect(xBoat+40, yBoat-20, 20, 20);        //boats cabin
  fill(0);
  text( boatscore, xBoat+45,yBoat-5);        //have score written on boat cabin
  text("Azelou", xBoat+25,yBoat+25);
}

  void bounceboat(){
  //BOUNCS BOAt ACROSS BACK FROM THE X-AXIS 
  xBoat= xBoat +dxBoat;
  if (xBoat > width) {    //makes the boat move though the x axis
    dxBoat=-1;
    xMoveboat= -1 * xMoveboat;      //change the nose direction by the old boat
    xRightboat=0;                  // resets position from the right at 0
    fill(0);
    text(boatscore, xBoat+20, yBoat+55);        //Boat score in the cabin
  }
  
  if (xBoat<0) {        /// bounces of  the beginning 
    dxBoat=1;
    xMoveboat= -1 * xMoveboat;        //polarity boat to left
    xRightboat=90;                //nose comes back to the front when it reaches x beginnig
  }
}
//float xCrawl=665; 565
//draw a crawler with different shapes on the
//right side of the ocean
void crawler() {
  fill(246, 250, 15);    //665 ,565
stroke(0);
strokeWeight(2);       // allows the line to be thicker
  ellipse(xCrawl+35, yCrawl+15, 70, 30);
  fill(255, 0, 0);            //color everything red
  rect(xCrawl, yCrawl, 5, 5);
  rect(xCrawl+60, yCrawl, 5, 5);
  rect(xCrawl, yCrawl+20, 5, 5);
  rect(xCrawl+60, yCrawl+20, 5, 5);
  line(xCrawl+30,yCrawl-15,xCrawl+30,yCrawl);
  text("BARSA", xCrawl+15,yCrawl+25);        // name the creepy crawler
  text( crawlscore, xCrawl+20, yCrawl+15);
 }
 void crawfishes()
 {
 if (mousePressed && mouseY>height/4){
   xCrawl= mouseX;
   if (dist(xCrawl,yCrawl, xFish,yFish)<80)
   {
     crawlscore= crawlscore+ 7 ;
     xCrawl=random(0,width);
     xFish=random(0,width/2);
     yFish=random(surface+40,height);
   
     }
   }
 }
 
 void crawkey(){
 
   if (keyPressed){
     if((key=='c' && dist(xCrawl, yCrawl, xFish, yFish)<100)){
       
      xCrawl= random(0, width);
      xFish= random(0, width/2);
      yFish= random(surface+30, height);
    crawlscore = crawlscore +7;
   
 }
   }
 }
  void keyPressed() {
  if (key == 'q')     ///This is statemetn is true only when q is pressed
    exit();            // exit the program when key pressed
  }

void message() {
  // MESSAGES: title & author  
  
  fill(0); 
  textSize(20);
 text(title , width/2,30);
   textSize(12);
   text( "CST112: TAKE HOME.", 15, 15 ); 
  text( "Kelly Hernandez, CST 112", 15, height-15 );
  text(  "BOAT:" + boatscore, 700, height-570);            /// score earned by each object
  text(  "TUNA:"+ tunascore, 700, height-555);
  text(  "CRAWLER:"+ crawlscore, 700, height-540);  
text("Catch fish by clicking on boat or crawler.", width/4,50); 
text("(Or use keys: 'b' for boat, 'c' for crawler, 'q' to quit.)",width/4,70 ); 

}
