// SAMUEL ROMAN             // |========||< NAVIGATE SOURCE >=====< CTRL+F >||======|
// CST 112 TEST 2           // |===|             [#XX] declarations             |===| 
// PROGRESS: COMPLETED      // |===| [#1.0] void setup      [#3.1] void fish    |===| 
                            // |===| [#2.0] void draw       [#3.2] void shark   |===| 
                            // |===| [#3.0] void scene      [#3.3] void octopus |===| 
                            // |====================================================|
//********************       
//[#XX] DECLARATIONS
//********************
int score=0;
int sunC=255;
int fishMany=6;
int octoW=80; 
int octoH=120;
float fishX=0, fishY=300, fishW=60, fishH=45, fishRed=200, fishSpacing=50;
float sharkX=500, sharkY=400, octoX=100, octoY=200;
float sunX=300, sunY=50, surface=100, waveX=0, waveY=surface;    
//********************
// [#1.0] VOID SETUP
//********************

void setup(){ 
 size(800,600);
 smooth();
 frameRate(30);
} 
//********************
// [#2.0] VOID DRAW   
//******************** 

void draw(){ 
  scene(); 
  fish();
  shark();
  octopus();
} 
//*********************
// [#3.0] VOID SCENE 
//*********************  

void scene(){
  // +| SKY |+
 background(200,200,255);
  // +|SCORE AT TOP|+
 fill(0);                 
 text(score,50,40);    
  // +|SUN || SUN COLOR|+
 fill(255,sunC,1);
 ellipse(sunX,sunY,80,80); 
   if(sunX>width) {
      sunX=300; //+|RESET SUN|+ 
      sunC=255; //+|RESET COLOR|+
     }
      else if(sunX<width) {
       sunX+=3; //+|MOVE SUN|+
       sunC--; // +|DECREASE COLOR|+
      }
  // +|WATER || WATER COLOR|+
 fill(0, 80, 10);            
  rect(0,surface,800,600);

  // +|WAVES MOVE|+
 waveX+=7; 
    if(waveX>width){ 
  // +|WAVES RESTART OFF SCREEN|+
       waveX=-500;  
     }
  // +|WAVE CLONES|+
float wx=waveX; 
   for(int i = 0; i < 3 ; i++)
    {// +|3 EXTRA WAVES|+ 
       fill(0,95,12);
       ellipse(wx,waveY,80,4);
       wx+=200;
    }
}
//*****[#3.1]******
//   VOID FISH 
//*****************

void fish(){ 

  // +|| RESET ALL FISH "IF" > PARAMETERS||+ 
 if(fishX>width||fishY>height||fishMany<1){ 
     fishMany=  2 + (int) random(6);     
     fishX= fishMany*fishSpacing;               
     fishY= surface+random(height/2);          
     fishW=  20+random(30);                
     fishH=  0.75 * fishW;            
     fishRed=  150 + (int) random(100);        
  } 
  // +|SLOPE 3/2|+  
     fishX+=3;  
     fishY+=2; 

  // +|GROUPIE FLOATS|+
float fishmX = fishX; float fishmY = fishY;
float fishmW = fishW; float fishmH = fishH;
    
  for (int i=0; i<fishMany; i++) 
    { // +|LEADER || GROUPIES|+
     fill(fishRed, 100, 180);
     ellipse(fishmX, fishmY, fishmW, fishmH);
     fishmX -= fishSpacing;
     fishmY += fishSpacing;
     fishmW -= 3;
     fishmH -= 2;
    }
   if ((fishMany>0) && (dist(fishX, fishY, octoX, octoY) < 50))
    { // +|OCTOPUS EATS FISH || SCORE+|
      background(0);
      fishMany -= 1;
      score += 50;
      fishX += 50;
    }
}
//******[#3.2]*******
//    VOID SHARK 
//*******************

void shark(){
  // +|SHARK|+
  fill(80);                     
  rect(sharkX,sharkY,160,45);  

  // +|SHARK MOVEMENT|+
float sharkmX = octoX - sharkX;
float sharkmY = octoY - sharkY;

  // +|SHARK CHASES OCTOPUS|+
  sharkX += sharkmX / 15;
  sharkY += sharkmY / 15;	       
    if (dist(sharkX, sharkY, octoX, octoY) < 50) 
    {// +|SHARK EATS OCTOPUS|| SCORE-|
      background(255);
      sharkX = width;
      sharkY = height;
      score -= 100;
     }
}
//*******[#3.3]*********   
//    VOID OCTOPUS
//**********************

void octopus() {
  // +|OCTOPUS FOLLOWS MOUSE|+
  octoX=mouseX;
  octoY=mouseY;
   
  // +|DRAW OCTOPUS || OCTOPUS COLOR|+
  fill(100,10,100);    
  rect(octoX,octoY,octoW,octoH);
 
  // +|OCTO LEG FLOATS|+
float legmX = octoX;
float legmY = octoY + 120;
float legZ = 0;
  
  // +|FEET POINT TOWARD SHARK|+
  if (sharkX > legmX + 50) legZ=-10;   
  if (sharkX < legmX - 50) legZ=+10;
    for (int i=0; i<8; i++) 
     { // +|MAKE 8 LEGS|+
      strokeWeight(3);
      line(legmX,legmY,legmX-legZ,legmY+20);
      legmX += 10;
     }
}










