//// Project 2 by Mario Baez ////
//// Fish and Boat ////
String title= "Project 2";
String author= "Mario Baez";
////////
float water;
float sunx=20, suny=50, sunDX=0.5, sunDY=0;
float mud;
float fishx=100, fishy=100, fishDX=3, fishDY=0;
float fishw=80, fishh=30;
float fishtailX;
float boatx=50,boaty=50, boatDX=2, boatDY=0;
float boatw=100, boath=40;
boolean day= true; 
int score=0;

//// SETUP ////
void setup() {
  size(800,600);
  rectMode(CORNERS);
  water= height/3;
  mud= height-12;
  boaty=water;
  resetFish();
}
void resetFish() {
  //
  fishy= random(water,mud);
  println(fishy);
  if (fishDX>0)  fishDX=  -random(5,10);
  else fishDX=  random(5,10);
  
}
void reset() { fishx=width; fishy=random(water+50, mud-20); fishDX= random(1,10);}

////DRAW////
void draw() {
  scene();
  fish();
  boat();
  //--  catches();
  msgs();
 
}
void scene() {
  if (day) { background(100,200,255); } //sky color
  else { background(50,100,150); }
  fill(255,255,0);
  ellipse(sunx,suny,50,50);
  sunx += sunDX;
  if (sunx > width+2) sunx= 0;
  if (sunx > width) day= false;
 // ocean
 fill(100,200,150);
 rect(0,water, width, mud);
 
fill(#D8C08A);
rect(width,900, 0 ,mud);
}

//// fish
void fish() {
  fishtailX=fishx-25;
  fill(250,130,10);     // fish color
  ellipse(fishx,fishy, 50,16);
  //triangle(fishtailX,fishy, fishtailX-20, fishy-12, fishtailX-20, fishy+12);
  if (fishDX>0){
     triangle(fishtailX,fishy, fishtailX-20, fishy-12, fishtailX-20, fishy+12);
  }
  else {
     triangle(fishtailX+50,fishy, fishtailX+70, fishy-12, fishtailX+70, fishy+12);
  }
  fishx += fishDX;
  if (fishx>width-20 || fishx<20) {
    resetFish();
  }
}

//// Boat
void boat() {
  fill(255,0,0);
  rectMode(CORNERS);
  rect(boatx,boaty,boatx+boatw,boaty-boath);
  float front= boatx+boatw, deck=water-boath;
  //triangle( front,water, front,deck , front+25,deck );
  if (boatDX>0){
    triangle( front,water, front,deck , front+25,deck );
  }
  else { triangle( front-100,water, front-100,deck , front-125,deck );
  }
    
  
  boatx+=boatDX;
  if (boatx>width-20 || boatx<20) {
    boatDX *= -1;
  }
}

//// Catches ////
void catches() {
  //--  if (dist(boatx,boaty,fishx, fishy) <50) {
  if ( abs(boatx-fishx) < 130) {
    score= score+ 5;
    score= score+10;
  }
}

////MSGS ////
void msgs() {
  fill(0);
  textSize(24);
  text( title, width-450,30);
  if (score>0) {
    text(score, width* 3/4, 40);
  }
  textSize(12);

  text( author, 700, height-20);
}


//// EVENTS ////
void keyPressed() {
  if (key== 'q' ) exit();
  if (key == 'n' ) day = ! day;
  if (key == 'c' ) resetFish(); 
}

void mousePressed() {
  if ( dist(mouseX,mouseY, boatx+boatw/2, boaty) < 40) {
    //--  background(0);
    catches();  
  }
}

