//// Project #1:  The birth of Isaac, and a glowy weird eye carlos chases him
    //// Juan Vaccalluzzo, CST 112, 2015 Feb 7

    // Global Declarations //
    float carlosX, carlosY;  // Location of the carlos
    float sunX, sunY;   // Location of the sun
    float sunDX = 3, sunDY; 
    float horizon; // Horizon relative to window size
    float isaacX, isaacY; //Isaac's position
    
    void setup() {
      //// Setup:  window size ////
      size( 600, 400 );
      smooth();
      frameRate( 30 );
      carlosX = width*4/5;
      carlosY = height*3.6/5;
      sunX = width*5/6;
      sunY = height/8;
      horizon = height/3;
      isaacX = pmouseX;
      isaacY = pmouseY;
      
    }

    void draw() {
      //// Next frame ////
      scene();
      isaac();
      carlos();
    }

    void scene() {
      //// Scene:  sky, sun, grass. Sun moves up and to the right
      //// and wraps around the screen
      sunX = sunX + sunDX; 
      sunX = sunX % width;
      sunY = horizon - 100*sin( PI * sunX/width); // Sun rises and falls
      horizon = height/3;
      
      background( 70, 226, 255 );  // Light blue sky.
      
      fill( 255, 50, 50 );
      text( " omg lolz nooooo ", width/3, height/8 );
      
      fill( 250, 255, 3 );         // Sun
      ellipseMode( CORNER );
      noStroke();
      ellipse( sunX, sunY, 60, 60 );
      
      
      fill( 22, 222, 57 );
      noStroke();                  // Grass
      rectMode(CORNER);
      rect( 0, horizon, width, height );  
      
      fill( 0 );                 // Header
      textSize( 25 );
      textAlign( BOTTOM, LEFT );
      text(" Juan Vaccalluzzo " , width/10, height*7/8 );
      
      fill( 255 );                // House
      rectMode( CORNER );
      stroke ( 0 );
      rect( 100, horizon, 100, 60 );
      fill( 255, 0, 0 );
      triangle( 100, horizon, 150, horizon-50, 200, horizon ); 
      noStroke();
      fill( 170, 114, 22 );
      rect( 135, horizon+30, 15, 32 );
      
     
    }
    
    void isaac()  {
      /// This is Isaac. He's my hero
      isaacX = mouseX;
      isaacY = mouseY;
      rectMode( CENTER );
      fill( 222, 22, 22 );  // Body
      stroke( 250, 255, 3 );
      strokeWeight( 2 );      
      rect( mouseX, mouseY, 30, 80 );
      
      ellipseMode( CENTER );  // Head
      fill( 222, 22, 22 );
      stroke( 250, 255, 3 );
      strokeWeight( 2 );
      ellipse( mouseX, mouseY-60, 25, 25 );
     
      rectMode( CENTER );    // Face Mask 
      fill( 150, mouseX, mouseY );
      rect( mouseX, mouseY-60, 20, 10 );
      
      stroke ( 222, 22, 22 );  // Legs
      strokeWeight( 3 );
      line( mouseX-10, mouseY+41, pmouseX-10, pmouseY+70 );
      line( mouseX+10, mouseY+41, pmouseX+10, pmouseY+70 );
      
      stroke ( 222, 22, 22 );  // Arms
      strokeWeight( 4 );
      line( mouseX-20, mouseY-30, mouseX-30, mouseY+20 );
      line( mouseX+20, mouseY-30, mouseX+30, mouseY+20 );
  }
    
    void carlos() {
      carlosX = carlosX + ( isaacX - carlosX ) / 30;
      carlosY = carlosY + ( isaacY - carlosY ) / 30;
      
      carlosY = carlosY < horizon-20 ? horizon + 20 : carlosY;

      
      fill( 0 );             // carlos's Body
      stroke( 200, 200, 200 );
      strokeWeight( 3 );
      ellipseMode( CENTER );
      ellipse( carlosX, carlosY, 80, 30 );
      
      fill( 255, mouseX, mouseY );  // Eye
      noStroke();
      ellipse( carlosX + ( mouseX - pmouseX ), carlosY + ( mouseY - pmouseY ), 40, 25 );
      
      stroke ( 0 );
      strokeWeight( 3 );
      line( carlosX-40, carlosY+5, carlosX-40, carlosY+40 ); 
      line( carlosX+40, carlosY+5, carlosX+40, carlosY+40 );     
      
    }
      
      void keyPressed() {
        if( key == 'q' ) exit();
      }    