////First project////
///Philip Lenz

String title="Philip Lenz, CST112, Project#1";

/// GLOBAL DATA ///
int sunX=600, sunY=125; //Position of sun
int birdX=100, birdY=100; //Start position of bird
int birdDX=5;
float bombX=0, bombY=0, bombDY=0;
float gravity= 9.8 / frameRate; //Bomb falling rate
int guyX=600, guyY=350, guyDX=5, guyDY=5;
int dogX=350, dogY=300;


void setup() {
  size(800, 600);
}


void draw() {
  //Move and illustrate everything
  scene();
  guy();
  dog();
  bird();
  bomb();
}

void scene() {
  //Backgroud// Sky, grass, sun
  background(65, 226, 240); //Sky
  fill (15, 188, 16);
  rectMode( CORNERS);
  rect( 0, height/2.5, width, height ); //Grass
  fill (255, 255, 0);
  ellipse(sunX, sunY, 50, 50); //Sun
 /// Sun Rising and Setting
  sunX = (sunX+1) % width;
  float  sun=  (float) sunX / width;
  sunY =  (int) ( 150 - 50*sin( PI*sun )   );
  
  //Text
  fill(0);
  text(title, 50, height-20);
}

void guy() {
  ///Guy moving
  guyDX=  guyX>50 && guyX<width-45 ? guyDX : -guyDX;
  guyDY=  guyY>height/2.5 && guyY<height-45 ? guyDY : -guyDY;
  guyX += guyDX;
  guyY += guyDY;
  //Drawing guy following mouse
  fill(255, 0 ,0);
  rectMode(CENTER);
  rect(guyX, guyY, 40, 65); //Body //Red shirt
  fill(237, 217, 151);
  ellipseMode(CENTER);
  ellipse(guyX, guyY-48, 30, 30);  //Head //Tan
  fill(55, 60, 180);
  rect(guyX+10, guyY+58, 15, 50);  //Leg 1 //Blue jeans
  rect(guyX-10, guyY+58, 15, 50);    //Leg 2 //Blue jeans
  ///Drawing eye
  fill(255);
  ellipse(guyX+8, guyY-53, 6, 6);
  fill(0);
  ellipse(guyX+9, guyY-53, 3, 3);
}

void dog() {
  //Drawing Dog 
  fill(124, 88, 15);
  rect(dogX-125, dogY+100, 50, 25);
  fill(124, 88, 15);
  rect(dogX-100, dogY+80, 25, 15);
  ///Chasing Guy
   dogX += (guyX-dogX) / 20;
   dogY += (guyY-dogY) / 25;
  
}

void bird() {
  //Drawing bird which will fly across screen
  fill(0);
  triangle( birdX, birdY, birdX-35, birdY-15, birdX-35, birdY+15); //Actual Bird

  //Bird flying
  birdX = birdX + birdDX;
  birdX = birdX % width;
 }


void bomb() {
  fill(126, 127, 129);
  ellipseMode( CENTER );
  triangle(bombX-10, bombY-22, bombX+10, bombY-22, bombX, bombY+15);
  fill(126, 127, 129);
  ellipse( bombX, bombY, 18, 30);

 //Bomb falling
    if (bombX > 0); {
    bombX=  birdX - 2;
    bombDY=  bombDY + gravity;
    bombY += bombDY;
}
    ///If bomb reaches bottom of screen it dissapears
    if (bombY > height) {
      bombDY=0;
 }
}

void keyPressed() {
  ///Bomb is dropped when key pressed
  bombX = birdX;
  bombY = birdY;
  bombDY = 0;
}
