//// Exam 1 Shooting Fish In a Barrel

String title= "Shooting Fish In A Bucket";
String author= "Mario Baez; exam 1";
String news= "";

//// GLOBAL DATA ////
float left=50, right, top = 100, bottom, bucketW, bucketH;
float fushX, fushY, fushDX;
float dogX, dogY;
//
float gunX;
float bulletX, bulletY;
int score =0;

//// SETUP ////
void setup() {
  size(800, 600);
  rectMode(CENTER);
  
  left =50;
  right =width-50;
  top =100;
  bottom =height-50;
  bucketW =right-left;
  bucketH =bottom-top;
  
  gunX= left + bucketW * .50;
  resetall();
  dogX= width/2;
  dogY= height-30;
  
}
void resetall() {
  // Reset fish, score, bullets
  reset();
  bulletY=0;
  score=0;
}
void reset() { fushX=left+25; fushY=random(top+50, bottom-20); fushDX= random(1,10); score= score-1;}

//// NEXT FRAME
void draw() {
  scene();
  show();
  action();
  hits();
  msgs();
}
void scene() {
  background( 200, 200, 255);
  // Bucket
  fill( 100, 255, 200);    // Water
  stroke(100);       // bucket color
  strokeWeight(20);
  rectMode(CORNER);
  rect(left,top,bucketW,bucketH);
  strokeWeight(1);
  stroke(0);
  // Gun
  fill(0);
  rect( gunX,top-40,12,80);
  
  fill(100,0,0);
  rect( gunX-25,top-40,30,15);
  fill(255);
}
//// SHOW: Fish, bullets
void show(){
  // bullets
  fill(0);
  if (bulletY>top) rect( bulletX,bulletY,5,10);
  
  float fushtailX;
  
  //FUSHES
  
  fushtailX=fushX-25;
  fill(250,130,10);     // fish color
  ellipse(fushX,fushY, 50,16);
  triangle(fushtailX,fushY, fushtailX-20, fushY-12, fushtailX-20, fushY+12);
  
 // Dog
 fill(0);
 ellipse(dogX,dogY,70,20);
 ellipse(dogX+30,dogY-8,25,15);
}

//// Action
void action() {
  // move fush
  fushX += fushDX;
  if (fushX>right) reset();
  
  if (bulletY>top) bulletY += 20;
  if (bulletY>bottom) bulletY=0;
}

//// HITS
void hits(){
  if (dist( bulletX,bulletY,fushX,fushY) < 30 ) {
    score= score + 50;
    news= "GOT EM";
    reset();
    background(255,255,0);
  }
}
//// MSGS: title, score
void msgs() {
  fill(0);
  textSize(24);
  text( title, width/3,30);
  if (score>0) {
    text(score, width* 3/4, 40);
  }
  textSize(12);
  text(news, 20, 50);
  text( author, 40, height-20);
}

//// EVENTS ////
void keyPressed() {
  if (key == 'q') exit();
  if (key== 'r') resetall();
  if (key == 'g') {bulletX=gunX; bulletY=top+10; score= score-5;}
}
void mousePressed() {
  if ( dist( mouseX,mouseY, gunX,top) < 50) {bulletX=gunX; bulletY=top+10; score= score-5;}
}
 
  


  