//// Exam 1 Shooting Fish In a Barrel

String title= "Shooting Fish In A Bucket";
String author= "Mario Baez; exam 1";
String news= "";
String help= " 'q' -quit, 'g'- shoot, 'r' -reset";

//// GLOBAL DATA ////
float left=50, right, top = 100, bottom, bucketW, bucketH;
float fushX, fushY, fushDX;
float fush2X, fush2Y, fush2DX;
float fush3X, fush3Y, fush3DX;
float fushtail3X;
float dogX, dogY, dogDX;

//
float gunX;
float bulletX, bulletY;
int score =0;
int hits=0;
int misses=0;


float buttonX, buttonY, buttonW, buttonH;
int buttonC;
String S = "HELP!";

//// 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();
  reset2();
  bulletY=0;
  score=0;
}
void reset() { fushX=left+25; fushY=random(top+50, bottom-20); fushDX= random(1,10); score= score-1; misses=misses+1;}
void reset2() { fush2X=right; fush2Y=random(top+50, bottom-20); fush2DX= random(1,10); score= score-1; misses=misses+1;}
void reset3() { fush3X=right; fush3Y=random(top+50, bottom-20); fush3DX= random(1,10); score= score-1; misses=misses+1;}

//// NEXT FRAME
void draw() {
  scene();
  show();
  action();
  hits();
  msgs();
  showButton();
}
void scene() {
  background( 40, 200, 0);
  // Bucket
  fill( 100, 255, 200);    // Water color
  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);
  
  // house 
  fill(220,100,0);
  rect(10,20,60,60);
  triangle(10,20, 20,5, 30,20);
  triangle(50,20, 60,5, 70,20);
  
  // tree
  fill(100,100,0);
  rect(700,35, 10,50);
  fill(0,130,0);
  ellipse(705,35, 40,40);
  
  // dead fish
  fill(0,130,180);     // fish color
  ellipse(90,bottom-10, 50,16);
  triangle(115,bottom-10, 135, bottom, 135, bottom-20);
  
  
}
//// SHOW: Fish, bullets
void show(){
  // bullets
  fill(0);
  if (bulletY>top) rect( bulletX,bulletY,5,10);
  
  float fushtailX;
  float fushtail2X;
  float fushtail3X;
 
  //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);
  
  fushtail2X=fush2X+25;
  fill(250,0,10);     // fish 2 color
  ellipse(fush2X,fush2Y, 50,16);
  triangle(fushtail2X,fush2Y, fushtail2X+20, fush2Y+12, fushtail2X+20, fush2Y-12);
  
 fushtail3X=fush3X+25;
  fill(250,200,230);     // fish 3 color
  ellipse(fush3X,fush3Y, 50,16);
  triangle(fushtail3X,fush3Y, fushtail3X+20, fush3Y+12, fushtail3X+20, fush3Y-12);
 
 
 
 
 
 // Dog
 fill(0);
 ellipse(dogX,dogY,70,20);
 fill(100,100,0);
 ellipse(dogX+30,dogY-8,25,15);
}
//// Button
void showButton()  {
  rectMode(CENTER);
  buttonX=width-100; buttonY=height-25; buttonW=100; buttonH=50;
  buttonC=255;
  fill( buttonC );
  rect( buttonX,buttonY , buttonW,buttonH , 20 );
  fill( 255, 0, 0 );
  text( S, buttonX-15, buttonY+5 );
  rectMode(CORNER);}
  
  
//// Action
void action() {
  // move fush
  fushX += fushDX;
  if (fushX>right)  reset(); 
  
  if (bulletY>top) bulletY += 20; 
  if (bulletY>bottom) bulletY=0; 
  
   fush2X += -fush2DX;
  if (fush2X<left+25)  reset2(); 
  
  fush3X += -fush3DX;
  if (fush3X<left+25)  reset3(); 
  
  
  // move dog
  dogX += random(-20,+20);
  dogY +=random(3);
  if (dogX>width || dogX<0) dogX=width/2;
    if (dogY>height || dogY<bottom-40) dogY=bottom+20;

}

//// HITS
void hits(){
  if (dist( bulletX,bulletY,fushX,fushY) < 30 ) {
    score= score + 50;
    news= "GOT EM";
    hits=hits+1;
    reset();
    background(255,255,0);
     } 
  if (dist( bulletX,bulletY,fush2X,fush2Y) < 30 ) {
    score= score + 50;
    news= "GOT EM";
    hits= hits+1;
    reset2();
    background(255,255,0);}
    
     if (dist( bulletX,bulletY,fush3X,fush3Y) < 30 ) {
    score= score + 50;
    news= "GOT EM";
    hits= hits+1;
    reset3();
    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);
  if (hits>0); {text(hits, width*3/4,60);}
  if (misses>0); {text(misses, width*3/4, 80);}
  if ( dist( mouseX,mouseY, buttonX, buttonY) <50) { text(help, width/2,height/2);}
 
}

//// 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;}
  if ( dist( mouseX,mouseY, dogX,dogY) < 50) {dogX= gunX- 30; dogY= top-20; bulletX=gunX; bulletY=top+10; score= score-5;}
 
}
 
  


  