String title="Shooting Fish in a Barrel";
String author="Kelmor Amaya; Exam #1";
String news="";


//data//

float left=50, right, top=100, bottom, bW, bH;
float fx, fy, fd; //F's in each means Fish//
float fx1,fy1,fd1;
float gun;
float bulletX, bulletY;
int score=0;

//setup//

void setup () { 
  size (900, 500);
  rectMode (CENTER); 
  //barrel//
  left =50;
  right= width-50;
  top= 100;
  bottom= height-50;
  bW= right-left;
  bH= bottom-top;
  //rifle
  gun= left+bW*0.25;
  resetall ();
}
void resetall () {
  reset1();
  reset2();
  bulletY=0;
  score=0;
}
//speed & random positions of fish//
void reset1 () { 
  fx=left+45; 
  fy=random(top+90, bottom-20); 
  fd=random (1, 19); 
  score=score-1;
}
void reset2 () {
  fx1=right+45;
  fy1=random(top+90, bottom-20);
  fd1=random (1,1);
  score=score-1;
}

void draw () {
  scene ();
  show ();
  action();
  msgs();
  bulletY=0;
  score=0;
}

// scene- barrel & gun;
void scene () {
  background (137, 158, 225);
  // barrel
  fill (173, 224, 250); //water
  stroke(138, 43, 226); //violet border//
  strokeWeight (10); //thickness of border//
  rectMode(CORNER);
  rect(left, top, bW, bH);
  strokeWeight (3);
  stroke (178, 34, 34); //redish border around fish//

  //rifle
  fill(255);    // white gun
  rect( gun, top-40, 12, 80 );
  fill(100, 124, 120);    // purple stock
  rect( gun-25, top-40, 30, 15 );
  fill(255);
  text( 1, gun-15, top-28 );
}
void show() {  

  // Draw the bullets
  fill(255,122,232);
  if (bulletY>top) rect( bulletX, bulletY, 5, 10 );
  float tailX;
  //
  tailX=fx-25;
  fill(250, 128, 114); //salmon fish//
  ellipse (fx, fy, 50, 16);
  triangle(tailX, fy, tailX-20, fy-12, tailX-20, fy+12);
  //purple fish
   tailX=fx1-27;
  fill( 144,96,146);
  ellipse( fx1,fy1, 70,30 );
  triangle( tailX,fy1, tailX-25,fy1-15,  tailX-25,fy1+15 );
}

void action () {
  fx+=fd;
  fd1+=fx1;
  if (fx>right) reset1();
  if (fx1>left) reset2();
  //

  if (bulletY>top) bulletY +=  20;
  if (bulletY>bottom) bulletY=0;
}

void msgs() {
  fill(255); 
  textSize(34);
  text( title, width/3, 30 );

  textSize(15);
  text( news, 10, 90);
  text( author, 40, height-20 );
}

void hits() {
  if ( dist( bulletX, bulletY, fx, fy )  <  20 ) 
    score=  score + 50;
  news=  "Salmon fish was caught";
  reset1();
  background( 255, 255, 0 );
}

void keyPressed() {
  if (key == 'q') exit();
  if (key == 'r') resetall();
  // Shoot
  if (key == '1') { 
    bulletX=gun; 
    bulletY=top+10; 
    score=score-5;
  }
}

void mousePressed() {

  if ( dist( mouseX, mouseY, gun, top ) < 50) { 
    bulletX=gun; 
    bulletY=top+10; 
    score=score-5;
  }
}
