class Player{

  PImage character;
  boolean jump;
  boolean walk;
  int walkLoop;
  int xPos = 0;
  int ground = 150;
  int yPos = ground;
  String level;
  int counter;
  int score, count, objC;
  int timer, demark;
  int health = 100;
  // controls
  int walkSpeed = 3;
  int jumpHeight = 10;
  int jumpUp = 10;
  int jumpDown = 7;
  boolean fall = false;
  String path = "";
  String[] walking = new String[3];



  void setup(){
    walking[0] = path+"walk1";
    walking[1] = path+"walk2";
    walking[2] = path+"stand";
  }

  void run(){
    if((jump)&&(counter < 3)){
      character = loadImage(path+"jumpA.png");
      counter++;
    }
    else if((jump)&&(counter >= 3)){
      character = loadImage(path+"jumpB.png");
      if((yPos > jumpHeight)&&(!fall)){
        yPos-=jumpUp;
        //        println("jumping");
      }
      else if((yPos <= jumpHeight)&&(!fall)){
        fall = true;
        //        println("fall");
      }
      if(fall){
        yPos+=jumpDown; 
      }
      if((yPos >= ground)&&(fall)){
        jump = false;
        fall = false;
        counter = 0;
        character = loadImage(path+"stand.png");
      }
    }
    image(character, xPos, yPos);
  }

  void animate(String state){
    if(state == "jump"){
      jump = true;
    }
    if((state == "right")&&(xPos < width-25)){
      xPos += walkSpeed; 
      walkLoop++;
      character = loadImage(walking[walkLoop%3]+".png");
    }
    else if((state == "left")&&(xPos+20 > 0)){
      xPos -= walkSpeed;
      walkLoop++;
      character = loadImage(walking[walkLoop%3]+"b.png"); 
    }else if(state == "dead"){
      character = loadImage(path+"dead.png"); 
    }
  }  

  void healthStat(int score, int count, int timer){
    if(timer > 800){
      demark = 4;
        level = "hard";
    }else if(timer > 400){
      demark = 3;
        level = "medium";
    }else{
       demark = 0; 
        level = "easy";  
  }
    
    if((count-score) < 8-demark){
        health += (count-score);
    }else{
        health -= (count-score)/2; 
    }

  }

}