////Anthony Porras- Project 2-Using objects
////Monster stalks the hero, who hunts for gold

String title="Project 2- Using objects";
String author=  "Anthony Porras";
//String score= "Score";

int sum=0;

//float xUlk=173, yUlk=161;
float xGold=360, yGold=250;
//float xMen=150, yMen=437;
//float xCliff=100, yCliff=300;
//float xCour=250, yCour=310;
int score=0, hero=0, monster=0;

Hero ulkatron;
Monster mennis;
Dog clifford;
Puppy courage;

//Declare sun variable to move
float sunX = 50;
float horizon;

//Global Coordinates
/*
float x=0;
float y=0;
float dx=1;
float dy=1;
*/

void setup() {
  //Set the size of the window
  size(800, 600);
  horizon= height/4;
  frameRate(30);
  //Instantiate the objects: hero, monster, dog, puppy.
  ulkatron= new Hero();
  mennis= new Monster();
  clifford= new Dog();
  courage= new Puppy();
  reset();
}

void reset() {
 //ulkatron.reset();
 //mennis.reset();
}

void draw() {
  //Draw a blue sky background
  background(3, 225, 252);
  
  scene();
  nugget();
  ulkatron.displayHero();
  //hero();
  mennis.displayMonster();
  //monster();
  clifford.displayDog();
  //dog();
  courage.displayPuppy();
  //puppy();
  ulkatron.action();
  mennis.action( ulkatron.x, ulkatron.y );
  clifford.action( ulkatron.x, ulkatron.y );
  courage.action( clifford.xCliff, clifford.yCliff );
}

////SCENE: grass, house, etc.
void scene() {
  //Draw a light green grass
  noStroke();
  fill(3, 252, 71);
  rectMode(CORNERS);
  //-- rect(0, 200, 600, 400);
  rect(0, horizon, width, height);

  //Draw a yellow sun
  noStroke();
  fill(240, 233, 17);
  ellipseMode(CENTER);
  ellipse(sunX, 50, 40, 40);
  sunX = sunX+2;
  if(sunX > width) {
    sunX = 0;

  }

  //Draw a tree with brown trunk
  noStroke();
  fill(185, 96, 11);
  rectMode(CORNERS);
  rect(460, 130, 480, 200);
  fill(26, 167, 2);
  ellipseMode(CENTER);
  ellipse(470, 100, 50, 100);

  //Draw a house
  noStroke();
  fill(242, 83, 120);
  rectMode(CORNERS);
  rect(100, 120, 250, 200);
  triangle(80, 120, 270, 120, 176, 50);

  //Draw windows on the house
  stroke(162);
  fill(255);
  rectMode(CENTER);
  rect(130, 140, 30, 30);
  rect(210, 140, 30, 30);

 
  //Draw a door on the house
  stroke(162);
  fill(193, 138, 240);
  rectMode(CORNERS);
  rect(155, 120, 190, 200);
  
  fill(0);
  text(title, width/3, 20);
  text(author, 10, height-10);
  text(score, 170, height-10);
  //text(sum, 210, height-10);
}

//Show nugget
void nugget() {
  //Draw gold nugget
  noStroke();
  fill(random(252, 147), 150, random(150));
  ellipseMode(CENTER);
  ellipse(xGold, yGold, 60, 30);


  //Set CENTER mode
  ellipseMode(CENTER);
  rectMode(CENTER);
}

//Show the hero
class Hero {
  float x=173, y=161;
  float dx=1,dy=1;
  //????
 float xUlk;
 float yUlk;
  Hero() {
    xUlk=173;
    yUlk=161;
    
  }
  
  void displayHero(){
  //Head
  stroke(0);
  fill(250, 233, 187);
  rect(x, y-13, 30, 30);

  //Body
  stroke(0);
  fill(19, 60, 160);
  ellipse(x, y+26, 45, 45);
  fill(255, 247, 3);
  text("Ulkatron", x-23, y+28);

  //Arms
  stroke(0);
  line(x-17, y+10, x-43, y+10);
  line(x+14, y+10, x+39, y+10);

  //Legs
  line(x-17, y+42, x-17, y+77);
  line(x+17, y+42, x+19, y+77);

  //Antenna
  stroke(0);
  fill(250, 3, 3);
  ellipse(x, y-44, 5, 5);
  line(x, y-39, x, y-28);

  //Eyes
  stroke(0);
  fill(255);
  ellipse(x-7, y-17, 10, 10);
  ellipse(x+7,y-17, 10, 10);

  fill(0, 0, 255);
  point(x+7, y-17);
  point(x-7, y-17);

  //Mouth
  line(x-7, y-3, x+7, y-3);
  }

  void action(){
     if(x>width) {
       x=0;
       y=0;
       dx=1;
       dy=1;
     }
     
     x= x + (xGold-x) / 30;
     y= y + (yGold-y) / 30;
     
     //Ulkatron found gold
     if( dist(x, y, xGold, yGold) < 30)
     {
       sum=sum + 100;
       restart();
     }
     else{
       sum=sum - 1;
     }
     
  }


}

//Show the monster
class Monster {
  float xMen;
  float yMen;
  Monster() {
    xMen=150;
    yMen=437;
  }
  
  void displayMonster() {
  //Body
  stroke(0);
  fill(250, 40, 8);
  rectMode(CENTER);
  rect(xMen, yMen, 39, 50);
  fill(103, 250, 195);
  text("Mennis", xMen-20, yMen);
  
  //Head
  stroke(0);
  fill(103, 250, 195);
  ellipseMode(CENTER);
  ellipse(xMen, yMen-37, 25, 25);
  
  //Arms
  line(xMen-20, yMen-25, xMen-50, yMen-7);
  line(xMen+20, yMen-25, xMen+45, yMen-7);
  
  //Legs
  line(xMen-20, yMen+8, xMen-20, yMen+38);
  line(xMen+19, yMen+8, xMen+19, yMen+38);
  
  //Eyes
  stroke(0);
  fill(8, 58, 250);
  ellipseMode(CENTER);
  ellipse(xMen-5, yMen-40, 8, 14);
  ellipse(xMen+5, yMen-40, 8, 14);
  }
    void action( float xx, float yy){     
       xMen= xMen + (xx-xMen) / 45;
       yMen= yMen + (yy-yMen) / 45;
    }
     

}

class Dog {
  float xCliff;
  float yCliff;
  float dx,dy;
  Dog() {
    xCliff=100;
    yCliff=300;
  }
  
  void displayDog() {
  //Body
  stroke(0);
  fill(149, 91, 29);
  rectMode(CENTER);
  rect(xCliff, yCliff, 60, 30);
  fill(250, 119, 119);
  text("Clifford", xCliff-20, yCliff);
  
  //Head
  stroke(0);
  fill(149, 91, 29);
  rectMode(CENTER);
  if (dx>0) {
    rect(xCliff+20, yCliff-28, 26, 26);
  }else{
    rect(xCliff-20, yCliff-28, 26, 26);
  }
  
  //Eye
  stroke(0);
  fill(245, 30, 159);
  ellipseMode(CENTER);
  ellipse(xCliff+25, yCliff-30, 6, 12);
  
  //Legs
  stroke(0);
  line(xCliff-30, yCliff+10, xCliff-30, yCliff+40);
  line(xCliff+30, yCliff+10, xCliff+30, yCliff+40);
  
  //Tail
  stroke(0);
  line(xCliff-50, yCliff-30, xCliff-30, yCliff-16);
  }
    void action( float xx, float yy){     
       dx= (xx-xCliff) / 25;
       dy= (yy-yCliff) / 25;
       xCliff += dx;
       yCliff += dy;
    }
}

class Puppy {
  float xCour;
  float yCour;
  Puppy() {
    xCour=250; 
    yCour=310;
  }
  
  void displayPuppy() {
  //Body
  stroke(0);
  fill(245, 30, 159);
  rectMode(CENTER);
  rect(xCour, yCour, 55, 22);
  fill(111, 52, 10);
  text("Courage", xCour-22, yCour+6);
  
  //Head
  stroke(0);
  fill(245, 30, 159);
  rectMode(CENTER);
  rect(xCour-20, yCour-23, 24, 24);
  
  //Eye
  stroke(0);
  fill(149, 91, 29);
  ellipseMode(CENTER);
  ellipse(xCour-24, yCour-24, 6, 12);
  
  //Legs
  stroke(0);
  line(xCour+26, yCour+12, xCour+26, yCour+25);
  line(xCour-28, yCour+12, xCour-28, yCour+25);
  
  //Tail
  stroke(0);
  line(xCour+26, yCour-12, xCour+44, yCour-20);
  }
    void action( float xx, float yy){     
       xCour= xCour + (xx-xCour) / 15;
       yCour= yCour + (yy-yCour) / 15;
    }
}


void restart() {
  //x= 50;
  //y= random(horizon, height);
  xGold=random(0, width);
  yGold=random(horizon, height);
  
  ulkatron.x=200;
  ulkatron.y=  horizon;
  
  mennis.xMen=  width-50;
  mennis.yMen=  height-50;
  
}

void mousePressed() {
  xGold= mouseX;
  yGold= mouseY;
  restart();
}