////p2 jack adrion
String title="Gone Fishing";
String by="Jack Adrion";
String reset="Press 'f' to restart";
String points="score:";
float left = 0, right = 900, top = 0, bottom = 900;
float Fish1X, Fish1Y, Fish1DX;
float Fish2X, Fish2Y, Fish2DX;
float BoatX, BoatDX;
float tailX, tail2X,sunX, moonX = left - 50;
float moonDX = 0;
float sunDX = 2;
float lineX, lineY;
int score=0;

void setup() {
  size( 900, 900 );
  rectMode(CENTER);
  top = 50;
  right = 900;
  resetall();
}
    
void resetall() {
  reset0();
  reset4();
  reset6();
}

void reset0() {  Fish2DX = 0 ;Fish2X = right + 50; Fish1X=left; Fish1Y=random(450 , 800); Fish1DX=random( 1, 10 ); score=0;}
void reset01() { Fish2DX = 0 ;Fish2X = right + 50; Fish1X=left; Fish1Y=random(450 , 800); Fish1DX=random( 1, 10 ); }
void reset1() { Fish2DX = 0 ;Fish2X = right + 50; Fish1X=left; Fish1Y=random(450 , 800); Fish1DX=random( 1, 10 ); score=score-1;}//f1
void reset2() { Fish1DX = 0 ;Fish1X = left-50; Fish2X=right; Fish2Y=random(450 , 800); Fish2DX=random( -1 , -10 ); score=score-1;}
void reset3() { BoatX=right; BoatDX=random (-2,-5); }
void reset4() { BoatX=left; BoatDX=random (2,5);}
void reset5() { sunX = left-50; sunDX=0; moonX = left; moonDX = 2;fill ( 150, 150, 255); rect (449,0,905,450);}//nighttime
void reset6() { moonX = left-50; moonDX = 0;sunX = left; sunDX=2;fill ( 150, 206, 255);rect (449,0,905,450);} //daytime

void draw() {
  scene();
  show();
  action();
  msgs();
  hits();
  hits2();
}

void scene() {
  background( 255,255,255 );
  fill ( 150, 206, 255);
  rect (449,0,905,450);
  fill (65,105,255);
  rect(448, 575, 905,700);
  fill (139,69,19);
  rect(448,900, 905,100);
  fill(255,255,0);
  ellipse(sunX,45,45,45);
  fill(255);
  ellipse(moonX,45,45,45);
}

void show() {
  fill(0);
  if (lineY>top) rect(lineX , lineY, 5 ,10);
  tailX=Fish1X-40;
  fill( 255,255,0 );
  ellipse( Fish1X,Fish1Y, 75,32 );
  triangle( tailX,Fish1Y, tailX-20,Fish1Y-12,  tailX-20,Fish1Y+12 );
  tail2X=Fish2X+40;
  fill( 255,255,0 );
  ellipse( Fish2X,Fish2Y, 75,32 );
  triangle( tail2X,Fish2Y, tail2X+20,Fish2Y-12,  tail2X+20,Fish2Y+12 );
  fill( 255,0,0 );
  rect( BoatX ,220, 100,50 );
}
   
void action() {
  moonX += moonDX;
  sunX += sunDX;
  Fish1X += Fish1DX;
  BoatX += BoatDX;
  Fish2X += Fish2DX;
  if (Fish1X>right+70) reset2();
  if (Fish2X<left-70) reset1();
  if (BoatX>right) reset3();
  if (BoatX<left) reset4();
  if (sunX>right) reset5();
  if (moonX>right) reset6();
  if (lineY>top) lineY +=  20;
  if (lineY>bottom) lineY=0;
}

void hits() {
  if ( dist( lineX,lineY, Fish2X,Fish2Y )  <  40 ) {
   score = score +5;
   reset01();
   background( 255,255,0 );
  } 
}
 
  void hits2(){
  if ( dist( lineX,lineY, Fish1X,Fish1Y )  <  40 ) {
   score = score +5;
   reset01(); 
   background( 255,255,0 );
 }
}

void msgs() {
  fill(0);
  textSize(24);
  text( title, width/2.5, 30 );
  textSize(12);
  text( by, 800, 880 );
  textSize(15);
  text( reset, 750, 25 );
  textSize(12);
  text( points, width/2.5, 45 );
  textSize(15);
  text( score, 400, 45 );
}

void keyPressed() {
  if (key == 'f') resetall();
  if (key == 'c') { lineX=BoatX; lineY=top+200; score=score-1; }
}


