//// Lenny Taveras Project 1
//// 10-1-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 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);
   action ();
   scene ();
   house ();
   dog ();
   hero ();
   credit ();
   
   
}  
  
  void scene() {
   fill ( 0, 253, 0);
   rect ( 0 , horizon , width, height-horizon);// grass
   fill ( 223, 255, 0);
   ellipse( sunX - 110, sunY, 150, 150 ); // Sun
   fill ( 173, 99, 21);
   rect ( 140, 330 , 20, 70); ///Trunk for the tree
   fill(24, 201, 93);
   ellipse ( 150, 320, 70, 70); // leaves for tree
 
 
}

  void house() {
    fill ( 255, 30, 30);
    rect ( 280, 300, 100, 100); // house body
    fill( 127, 0, 0);
    triangle ( 270, 310, 330, 255, 390,310 ); // roof
    fill (23,0,150);
    rect ( 315, 350, 25, 50); // door

    
}    
  
  void hero () {
    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 dog () { 
    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);
}    
