//// Lenny Taveras Project 2
//// 10-16-2019 CST 112

String title=  "A Dogs Awakening ";
String author=  "Lenny Taveras";

float horizon;
float sunX;
float sunY;
float heroX=325,heroY=450, heroDX=2, heroDY=1;
float dogX, dogY, dogDX, dogDY; 
float houseX=280, houseY=300;
float treeX=140, treeY=330;
float rate;
 
  void setup() { 
   size (600, 600);
   horizon = 400;
   reset ();
   dogReset();
}

  void reset () {
   sunX=0;
   sunY=40;
}
  void dogReset () {
   rate=  frameRate;
   dogX=  random(width/2, width-50);
   dogY=  random(horizon, height-20);
   
}

  void draw () {
   background(150,200,240); //sky
   action ();
   scene ();
   showSun ( sunX, sunY);
   showTree (treeX, treeY);
   showHouse (houseX, houseY);
   showDog (dogX, dogY);
   showHero( heroX, heroY);
   credit ();
   
   
}  
  
  void scene() {
   fill ( 0, 253, 0);
   rect ( 0 , horizon , width, height-horizon);// grass
}
  void showSun ( float sunX, float sunY) { 
   fill ( 223, 255, 0);
   ellipse( sunX - 110, sunY, 150, 150 ); // Sun
   
}
 
   
   void showTree(float treeX, float treeY) {
   fill ( 173, 99, 21);
   rect ( treeX, treeY , 20, 70); ///Trunk for the tree
   fill(24, 201, 93);
   ellipse ( treeX + 10, treeY - 10, 70, 70); // leaves for tree
 }

  void showHouse(float houseX, float houseY) {
    fill ( 255, 30, 30);
    rect ( houseX, houseY, 100, 100); // house body
    fill( 127, 0, 0);
    triangle ( houseX - 15, houseY + 10, houseX + 50, houseY - 45, houseX + 120, houseY + 10 ); // roof
    fill (23,0,150);
    rect ( houseX + 35, houseY + 50, 25, 50); // door

    
}    
  
  void showHero (float heroX, float heroY) {
    
    fill ( 59, 178, 232);
    rect ( heroX, heroY, 30, 60); //body
    fill ( 200);
    ellipse ( heroX + 15, heroY - 4, 35, 35); //head
    fill ( 63, 184, 216); 
    ellipse ( heroX + 9, heroY - 5, 6, 6);  // left eye
    ellipse ( heroX + 21, heroY - 5, 6, 6);  // right eye
    line ( heroX + 10, heroY + 2, heroX +20, heroY +2); //lips
   
}    
  void showDog (float dogX, float dogY) { 
    fill (227, 153, 16);
    rect ( dogX - 50, dogY, 50, 25); // dog body
    fill (0);
    rect ( dogX - 50 , dogY + 25, 10, 13);// legs
    rect ( dogX - 10 , dogY + 25, 10, 13);
    fill (227, 153, 16);
    rect ( dogX, dogY, 20, 15); // head
    fill (0);
    ellipse ( dogX + 5, dogY + 5, 3, 3); // eyes
    line ( dogX + 20, dogY + 10, dogX + 15, dogY + 10); //lips
  
}
  void action() {              
                            // Moves hero on screen
    if (heroX>width || heroX<10) { heroDX = - heroDX; } 
  heroX = heroX + heroDX;
    if (heroY>height || heroY<horizon) { heroDY = - heroDY; }
  heroY = heroY + heroDY;
  
   dogDX=  (heroX-dogX) / rate / 2; // dog follows hero
   dogDY=  (heroY-dogY) / rate / 3;
   dogX=  dogX + dogDX;
   dogY=  dogY + dogDY;
    
   sunX =  sunX + 1;  // Sun moves across sky
  
   if (sunX > 800) { 
   reset();}
   // Sun resets greater than 800p  
} 

  void credit () {
    
    fill(0);
    textSize(20);
    text( title, width/3, 24); 
    textSize(12);
    fill(150,0,0);
    text( author, 20, height-20);
}    