Your browser does not support the canvas tag.

previous        Show / Hide Source        Download        next
Character Knight;
drawBackground castle;
Platform platform;
Attack smite;
Enemy darkKnight;

void setup() {
  rectMode(CORNERS);
  size (400, 400);
  Knight = new Character();
  darkKnight = new Enemy();
  castle = new drawBackground();
  platform = new Platform(150, 310, 250, 300);
  smite = new Attack();
  instructions();
}

void draw() {
  castle.display();
  Knight.keyReleased();
  Knight.keyPressed();
  Knight.movement();
  Knight.border();
  Knight.checkForCollisionVsPlatform();
  darkKnight.knockback();
  darkKnight.Movement();
  

  platform.display();
  Knight.player();
  Knight.Health();
  darkKnight.Display();
  darkKnight.healthBar();
  smite.swing();


}

void instructions()
{
  println("WASD to move");
  println("'j': stun 'k': slash");
}
class Attack
{
  boolean slash;
  boolean knockback;
  int slashRight;

  Attack() {
    slash = false;
    slashRight = 1;
  }






  void swing() {
    if (keyPressed) {

      {
        if (key == 'k') {
          slash = true;
          if (slash) 
          {
            if (Knight.facingRight == 1)
            {
              slashRight = 1;
              key = 's';
            } else if (Knight.facingRight == 0)
            {
              slashRight = -1;
              key = 's';
            }

            noStroke();
            fill(255);
            rect(Knight.location.x + 60 * slashRight, Knight.location.y -50, Knight.location.x + 80 * slashRight, Knight.location.y -45);
            rect(Knight.location.x + 65 * slashRight, Knight.location.y -45, Knight.location.x + 100 * slashRight, Knight.location.y -40);
            rect(Knight.location.x + 95 * slashRight, Knight.location.y -55, Knight.location.x + 105 * slashRight, Knight.location.y -50);
            slash = false;
          }
        }
      }
    }
  }
}
class Character 
{
  // x and y coordinates
  PVector location;
  // x and y speed
  PVector velocity;
  float ground;
  float gravity;
  float jumpHeight;
  float moveSpeed;
  float maxFallSpeed;
  float HP;
  boolean moveLeft;
  boolean moveRight;
  boolean jump;
  boolean grounded;
  boolean Alive;
  int facingRight;
  int lookingRight;

  Character() 
  {
    gravity = 0.1;
    ground = 350;
    jumpHeight = 3.5;
    moveSpeed = 3;
    maxFallSpeed = 10;
    moveLeft = false;
    moveRight = false;
    jump = false;
    grounded = true;
    facingRight = 1;
    lookingRight = 1;
    HP = 100;
    Alive = true;

    location = new PVector (100, 350);
    // X speed and Y speed
    velocity = new PVector (moveSpeed, 2);
  }

  void movement() 
  {
    // Make the character recieve gravity when he is not on the ground
    if (grounded == false) 
    {
      // gravity on the character
      location.y += velocity.y;
      velocity.y += gravity;
      // falling speed cap
      if (velocity.y > maxFallSpeed)
      {
        velocity.y = maxFallSpeed;
      }
    } else
    {
      //reset character y velocity
      velocity.y = 0;
    }

    // Make the character move when 'w' 'a' or 'd' are pressed
    if (moveLeft == true) 
    {
      location.x -= moveSpeed;
      moveLeft = false;
    } else if (moveRight == true) 
    {
      location.x += moveSpeed;
      moveRight = false;
    } 
    if (jump == true && (grounded == false)) 
    {

      location.y -= jumpHeight;
      jump = false;
    }
  }




  void Health() {
    if (Alive) {
      fill (255, 0, 0);
      rect(location.x-40, location.y - 150, location.x-40 + HP, location.y - 140);
    }
    if (!darkKnight.Dead) {
      if (darkKnight.Position.x < location.x + 20 && darkKnight.Position.x > location.x - 20 && location.y > 340) {
        HP -= 1;
      }
    }
    if (HP < 1)
    {
      HP = 0;
      Alive = false;
    }
  }





  void keyPressed() 
  {
    // player moves left and right when a and d are pressed
    if (keyPressed) 
    {
      if ((key == 'a') || (key == 'A')) 
      {
        moveLeft = true;
        facingRight = 0;
      } else if ((key == 'd') || (key == 'D')) 
      {
        moveRight = true;
        facingRight = 1;
      }
      // Make character jump
      if ((key == 'w') || (key == 'W')) 
      {
        jump = true;
        grounded = false;
      }
    }
  }





  void keyReleased() 
  {
    if ((key == 'a') || (key == 'A')) 
    {
      moveLeft = false;
    } else if ((key == 'd') || (key == 'D')) 
    {
      moveRight = false;
    } else if ((key == 'w') || (key == 'W')) 
    {
      jump = false;
    }
  }


  void checkForCollisionVsPlatform()
  {
    //println((location.y <= platform.bottom+10), (location.y >= platform.top-10), (location.x >= platform.left), (location.x <= platform.right));



    if ((location.y <= platform.bottom+10) && (location.y >= platform.top-10) && (location.x >= platform.left) && (location.x <= platform.right))
    {
      grounded = true;
      location.y = platform.top - 10;
      //println("Grounded");
    } else if (((location.x < platform.left) && (location.y < ground - 10)) || ((location.x > platform.right) && (location.y < ground - 10)))
    {
      grounded = false;
    }
    stroke(255, 0, 0);
    point(location.x, location.y);
  }

  void border() 
  {
    // ground
    if (location.y >= 350)
    {
      grounded = true;
    }
    if (location.x < 0) 
    {
      location.x = 0;
    } else if (location.x > width - 10) 
    {
      location.x = width - 10;
    } else if (location.y > ground)
    {
      location.y = 350;
    }
  }

  void player() 
  {
    if (facingRight == 1)
    {
      fill(0);

      noStroke();
      //head
      rect(location.x - 5 * lookingRight, location.y - 125, location.x + 15 * lookingRight, location.y - 120);
      rect(location.x - 10 * lookingRight, location.y - 120, location.x + 15 * lookingRight, location.y - 115);
      rect(location.x - 15 * lookingRight, location.y - 115, location.x + 25 * lookingRight, location.y - 110);  
      rect(location.x - 20 * lookingRight, location.y - 110, location.x + 25 * lookingRight, location.y - 90);
      rect(location.x - 20 * lookingRight, location.y - 100, location.x + 25 * lookingRight, location.y - 75);
      rect(location.x - 20 * lookingRight, location.y - 90, location.x + 20 * lookingRight, location.y - 70);

      if (Alive)
      {
        fill(#ffffff);
        rect(location.x - 5 * lookingRight, location.y - 120, location.x + 10 * lookingRight, location.y - 115);
        fill(#c9c9c9);
        rect(location.x + 5 * lookingRight, location.y - 120, location.x + 10 * lookingRight, location.y - 115);
        rect(location.x - 10 * lookingRight, location.y - 115, location.x, location.y - 110);
        rect(location.x - 15 * lookingRight, location.y - 110, location.x- 5 * lookingRight, location.y - 100);
        rect(location.x - 15 * lookingRight, location.y - 100, location.x- 10 * lookingRight, location.y - 95);
        rect(location.x, location.y - 110, location.x + 5 * lookingRight, location.y - 100);
        rect(location.x + 5 * lookingRight, location.y - 110, location.x + 15 * lookingRight, location.y - 105);
        rect(location.x + 10 * lookingRight, location.y - 115, location.x + 15 * lookingRight, location.y - 105);
        rect(location.x + 20 * lookingRight, location.y - 105, location.x + 25 * lookingRight, location.y - 110);

        fill(#8e8e8e);
        rect(location.x - 15 * lookingRight, location.y - 95, location.x - 10 * lookingRight, location.y - 75);
        rect(location.x - 10 * lookingRight, location.y - 100, location.x - 5 * lookingRight, location.y - 95);
        rect(location.x - 5 * lookingRight, location.y - 95, location.x + 25 * lookingRight, location.y - 90);
        rect(location.x, location.y - 100, location.x + 5 * lookingRight, location.y - 95);
        rect(location.x + 10 * lookingRight, location.y - 105, location.x + 15 * lookingRight, location.y - 95);
        rect(location.x + 20 * lookingRight, location.y - 105, location.x + 25 * lookingRight, location.y - 95);
        fill(#ff9e9e);
        rect(location.x - 5 * lookingRight, location.y - 85, location.x + 20 * lookingRight, location.y - 80);
        rect(location.x, location.y - 80, location.x + 20 * lookingRight, location.y - 75);
      }

      //body
      fill(0);
      rect(location.x - 15 * lookingRight, location.y - 70, location.x + 25 * lookingRight, location.y - 25);
      rect(location.x - 10 * lookingRight, location.y - 25, location.x + 20 * lookingRight, location.y - 20);

      if (Alive)
      {
        fill(#c9c9c9);
        rect(location.x - 10 * lookingRight, location.y - 70, location.x + 20 * lookingRight, location.y - 25);
        fill(#8e8e8e);
        rect(location.x - 10 * lookingRight, location.y - 65, location.x + 10 * lookingRight, location.y - 25);
        rect(location.x - 10 * lookingRight, location.y - 60, location.x + 20 * lookingRight, location.y - 25);
      }

      //legs

      fill(0);
      rect(location.x - 10 * lookingRight, location.y - 20, location.x - 5 * lookingRight, location.y - 5);
      rect(location.x - 15 * lookingRight, location.y - 10, location.x - 5 * lookingRight, location.y - 5);
      rect(location.x - 15 * lookingRight, location.y - 10, location.x - 10 * lookingRight, location.y - 0);
      rect(location.x + 20 * lookingRight, location.y - 25, location.x + 25 * lookingRight, location.y - 0);

      //right arm
      fill(0);
      rect(location.x - 25 * lookingRight, location.y - 70, location.x, location.y - 55);
      rect(location.x - 30 * lookingRight, location.y - 65, location.x - 5 * lookingRight, location.y - 50);
      rect(location.x - 35 * lookingRight, location.y - 50, location.x - 15 * lookingRight, location.y - 40);
      rect(location.x - 40 * lookingRight, location.y - 40, location.x - 20 * lookingRight, location.y - 25);

      if (Alive)
      {
        fill(#8e8e8e);
        rect(location.x - 15 * lookingRight, location.y - 70, location.x - 5 * lookingRight, location.y - 60);
        rect(location.x - 25 * lookingRight, location.y - 65, location.x - 10 * lookingRight, location.y - 55);  
        rect(location.x - 30 * lookingRight, location.y - 50, location.x - 15 * lookingRight, location.y - 45);
        rect(location.x - 30 * lookingRight, location.y - 45, location.x - 20 * lookingRight, location.y - 40);

        fill(#c9c9c9);
        rect(location.x - 15 * lookingRight, location.y - 70, location.x - 5 * lookingRight, location.y - 65);
        rect(location.x - 25 * lookingRight, location.y - 65, location.x - 15 * lookingRight, location.y - 60);
        rect(location.x - 35 * lookingRight, location.y - 40, location.x - 25 * lookingRight, location.y - 30);

        fill(#ffffff);    
        rect(location.x - 15 * lookingRight, location.y - 70, location.x - 10 * lookingRight, location.y - 65);
        rect(location.x - 25 * lookingRight, location.y - 65, location.x - 20 * lookingRight, location.y - 60);

        rect(location.x - 35 * lookingRight, location.y - 40, location.x - 30 * lookingRight, location.y - 35);
      }

      //left arm
      fill(0);
      rect(location.x + 25 * lookingRight, location.y - 75, location.x + 35 * lookingRight, location.y - 50);
      rect(location.x + 35 * lookingRight, location.y - 70, location.x + 40 * lookingRight, location.y - 55);

      if (Alive)
      {
        fill(#8e8e8e);
        rect(location.x + 30 * lookingRight, location.y - 70, location.x + 35 * lookingRight, location.y - 55);

        fill(#c9c9c9);
        rect(location.x + 30 * lookingRight, location.y - 70, location.x + 35 * lookingRight, location.y - 65);
      }

      //sword
      fill(0);
      rect(location.x - 30 * lookingRight, location.y - 40, location.x - 20 * lookingRight, location.y - 20);
      rect(location.x - 20 * lookingRight, location.y - 40, location.x - 10 * lookingRight, location.y - 25);
      rect(location.x - 10 * lookingRight, location.y - 45, location.x, location.y - 30);
      rect(location.x, location.y - 50, location.x + 15 * lookingRight, location.y - 35);
      rect(location.x + 15, location.y - 55, location.x + 30, location.y - 40);

      if (Alive)
      {
        fill(#ffffff);
        rect(location.x - 25 * lookingRight, location.y - 35, location.x - 20 * lookingRight, location.y - 25);
        rect(location.x - 20 * lookingRight, location.y - 35, location.x - 10 * lookingRight, location.y - 30);   
        rect(location.x - 10 * lookingRight, location.y - 40, location.x, location.y - 35);
        rect(location.x, location.y - 45, location.x + 15, location.y - 40);
        rect(location.x + 15, location.y - 50, location.x + 30, location.y - 45);
      }

      //shield
      if (keyPressed)
      {
        if (key == 'j')
        {
          fill(0);
          rect(location.x + 40, location.y - 95, location.x + 65, location.y - 90);
          rect(location.x + 35, location.y - 90, location.x + 65, location.y - 85);
          rect(location.x + 35, location.y - 85, location.x + 65, location.y - 45);
          rect(location.x + 35, location.y - 45, location.x + 65, location.y - 35);
          rect(location.x + 40, location.y - 35, location.x + 65, location.y - 25);
          rect(location.x + 45, location.y - 25, location.x + 65, location.y - 20);
          rect(location.x + 50, location.y - 20, location.x + 60, location.y - 15);
          if (Alive)
          {
            fill(#c9c9c9);
            rect(location.x + 35, location.y - 85, location.x + 40, location.y - 45);
            rect(location.x + 40, location.y - 70, location.x + 45, location.y - 35);
            rect(location.x + 45, location.y - 35, location.x + 50, location.y - 25);
            rect(location.x + 50, location.y - 25, location.x + 60, location.y - 20);
            rect(location.x + 45, location.y - 85, location.x + 60, location.y - 80);

            fill(#ffffff);
            rect(location.x + 40, location.y - 90, location.x + 60, location.y - 85);
            rect(location.x + 35, location.y - 85, location.x + 45, location.y - 80);

            fill(#0300bb);
            rect(location.x + 50, location.y - 65, location.x + 60, location.y - 25);
            rect(location.x + 45, location.y - 65, location.x + 60, location.y - 35);
            rect(location.x + 40, location.y - 60, location.x + 60, location.y - 50);

            fill(#0f36ff);
            rect(location.x + 50, location.y - 65, location.x + 60, location.y - 45);
            rect(location.x + 55, location.y - 65, location.x + 60, location.y - 35);

            fill(#1333d9);
            rect(location.x + 50, location.y - 85, location.x + 60, location.y - 65);
            rect(location.x + 40, location.y - 80, location.x + 60, location.y - 70);
            rect(location.x + 45, location.y - 70, location.x + 60, location.y - 65);

            fill(#f0ff00);
            rect(location.x + 50, location.y - 70, location.x + 60, location.y - 65);
            rect(location.x + 55, location.y - 65, location.x + 60, location.y - 60);
            rect(location.x + 55, location.y - 55, location.x + 60, location.y - 50);
          }
        }
      }
    } else
    {
      fill(0);
      noStroke();
      //head
      rect(location.x - 5 * -1, location.y - 125, location.x + 15 * -1, location.y - 120);
      rect(location.x - 10 * -1, location.y - 120, location.x + 15 * -1, location.y - 115);
      rect(location.x - 15 * -1, location.y - 115, location.x + 25 * -1, location.y - 110);  
      rect(location.x - 20 * -1, location.y - 110, location.x + 25 * -1, location.y - 90);
      rect(location.x - 20 * -1, location.y - 100, location.x + 25 * -1, location.y - 75);
      rect(location.x - 20 * -1, location.y - 90, location.x + 20 * -1, location.y - 70);

      if (Alive)
      {
        fill(#ffffff);
        rect(location.x - 5 * -1, location.y - 120, location.x + 10 * -1, location.y - 115);
        fill(#c9c9c9);
        rect(location.x + 5 * -1, location.y - 120, location.x + 10 * -1, location.y - 115);
        rect(location.x - 10 * -1, location.y - 115, location.x, location.y - 110);
        rect(location.x - 15 * -1, location.y - 110, location.x- 5 * -1, location.y - 100);
        rect(location.x - 15 * -1, location.y - 100, location.x- 10 * -1, location.y - 95);
        rect(location.x, location.y - 110, location.x + 5 * -1, location.y - 100);
        rect(location.x + 5 * -1, location.y - 110, location.x + 15 * -1, location.y - 105);
        rect(location.x + 10 * -1, location.y - 115, location.x + 15 * -1, location.y - 105);
        rect(location.x + 20 * -1, location.y - 105, location.x + 25 * -1, location.y - 110);

        fill(#8e8e8e);
        rect(location.x - 15 * -1, location.y - 95, location.x - 10 * -1, location.y - 75);
        rect(location.x - 10 * -1, location.y - 100, location.x - 5 * -1, location.y - 95);
        rect(location.x - 5 * -1, location.y - 95, location.x + 25 * -1, location.y - 90);
        rect(location.x, location.y - 100, location.x + 5 * -1, location.y - 95);
        rect(location.x + 10 * -1, location.y - 105, location.x + 15 * -1, location.y - 95);
        rect(location.x + 20 * -1, location.y - 105, location.x + 25 * -1, location.y - 95);
        fill(#ff9e9e);
        rect(location.x - 5 * -1, location.y - 85, location.x + 20 * -1, location.y - 80);
        rect(location.x, location.y - 80, location.x + 20 * -1, location.y - 75);
      }

      //body
      fill(0);
      rect(location.x - 15* -1, location.y - 70, location.x + 25* -1, location.y - 25);
      rect(location.x - 10* -1, location.y - 25, location.x + 20* -1, location.y - 20);
      if (Alive)
      {      
        fill(#c9c9c9);
        rect(location.x - 10* -1, location.y - 70, location.x + 20* -1, location.y - 25);
        fill(#8e8e8e);
        rect(location.x - 10* -1, location.y - 65, location.x + 10* -1, location.y - 25);
        rect(location.x - 10* -1, location.y - 60, location.x + 20* -1, location.y - 25);
      }

      //legs
      fill(0);
      rect(location.x - 10* -1, location.y - 20, location.x - 5* -1, location.y - 5);
      rect(location.x - 15* -1, location.y - 10, location.x - 5* -1, location.y - 5);
      rect(location.x - 15* -1, location.y - 10, location.x - 10* -1, location.y - 0);
      rect(location.x + 20* -1, location.y - 25, location.x + 25* -1, location.y - 0);

      //right arm
      fill(0);
      rect(location.x - 25* -1, location.y - 70, location.x, location.y - 55);
      rect(location.x - 30* -1, location.y - 65, location.x - 5* -1, location.y - 50);
      rect(location.x - 35* -1, location.y - 50, location.x - 15* -1, location.y - 40);
      rect(location.x - 40* -1, location.y - 40, location.x - 20* -1, location.y - 25);

      if (Alive)
      {
        fill(#8e8e8e);
        rect(location.x - 15* -1, location.y - 70, location.x - 5* -1, location.y - 60);
        rect(location.x - 25* -1, location.y - 65, location.x - 10* -1, location.y - 55);  
        rect(location.x - 30* -1, location.y - 50, location.x - 15* -1, location.y - 45);
        rect(location.x - 30* -1, location.y - 45, location.x - 20* -1, location.y - 40);

        fill(#c9c9c9);
        rect(location.x - 15* -1, location.y - 70, location.x - 5* -1, location.y - 65);
        rect(location.x - 25* -1, location.y - 65, location.x - 15* -1, location.y - 60);
        rect(location.x - 35* -1, location.y - 40, location.x - 25* -1, location.y - 30);

        fill(#ffffff);    
        rect(location.x - 15* -1, location.y - 70, location.x - 10* -1, location.y - 65);
        rect(location.x - 25* -1, location.y - 65, location.x - 20* -1, location.y - 60);

        rect(location.x - 35* -1, location.y - 40, location.x - 30* -1, location.y - 35);
      }

      //left arm
      fill(0);
      rect(location.x + 25* -1, location.y - 75, location.x + 35* -1, location.y - 50);
      rect(location.x + 35* -1, location.y - 70, location.x + 40* -1, location.y - 55);

      if (Alive)
      {
        fill(#8e8e8e);
        rect(location.x + 30* -1, location.y - 70, location.x + 35* -1, location.y - 55);

        fill(#c9c9c9);
        rect(location.x + 30* -1, location.y - 70, location.x + 35* -1, location.y - 65);
      }

      //sword
      fill(0);
      rect(location.x - 30* -1, location.y - 40, location.x - 20* -1, location.y - 20);
      rect(location.x - 20* -1, location.y - 40, location.x - 10* -1, location.y - 25);
      rect(location.x - 10* -1, location.y - 45, location.x, location.y - 30);
      rect(location.x, location.y - 50, location.x + 15* -1, location.y - 35);
      rect(location.x + 15* -1, location.y - 55, location.x + 30* -1, location.y - 40);
      if (Alive)
      {
        fill(#ffffff);
        rect(location.x - 25* -1, location.y - 35, location.x - 20* -1, location.y - 25);
        rect(location.x - 20* -1, location.y - 35, location.x - 10* -1, location.y - 30);   
        rect(location.x - 10* -1, location.y - 40, location.x, location.y - 35);
        rect(location.x, location.y - 45, location.x + 15* -1, location.y - 40);
        rect(location.x + 15* -1, location.y - 50, location.x + 30* -1, location.y - 45);
      }

      //shield
      if (keyPressed)
      {
        if (key == 'j')
        {
          fill(0);
          rect(location.x + 40* -1, location.y - 95, location.x + 65* -1, location.y - 90);
          rect(location.x + 35* -1, location.y - 90, location.x + 65* -1, location.y - 85);
          rect(location.x + 35* -1, location.y - 85, location.x + 65* -1, location.y - 45);
          rect(location.x + 35* -1, location.y - 45, location.x + 65* -1, location.y - 35);
          rect(location.x + 40* -1, location.y - 35, location.x + 65* -1, location.y - 25);
          rect(location.x + 45* -1, location.y - 25, location.x + 65* -1, location.y - 20);
          rect(location.x + 50* -1, location.y - 20, location.x + 60* -1, location.y - 15);

          if (Alive)
          {
            fill(#c9c9c9);
            rect(location.x + 35* -1, location.y - 85, location.x + 40* -1, location.y - 45);
            rect(location.x + 40* -1, location.y - 70, location.x + 45* -1, location.y - 35);
            rect(location.x + 45* -1, location.y - 35, location.x + 50* -1, location.y - 25);
            rect(location.x + 50* -1, location.y - 25, location.x + 60* -1, location.y - 20);
            rect(location.x + 45* -1, location.y - 85, location.x + 60* -1, location.y - 80);

            fill(#ffffff);
            rect(location.x + 40* -1, location.y - 90, location.x + 60* -1, location.y - 85);
            rect(location.x + 35* -1, location.y - 85, location.x + 45* -1, location.y - 80);

            fill(#0300bb);
            rect(location.x + 50* -1, location.y - 65, location.x + 60* -1, location.y - 25);
            rect(location.x + 45* -1, location.y - 65, location.x + 60* -1, location.y - 35);
            rect(location.x + 40* -1, location.y - 60, location.x + 60* -1, location.y - 50);

            fill(#0f36ff);
            rect(location.x + 50* -1, location.y - 65, location.x + 60* -1, location.y - 45);
            rect(location.x + 55* -1, location.y - 65, location.x + 60* -1, location.y - 35);

            fill(#1333d9);
            rect(location.x + 50* -1, location.y - 85, location.x + 60* -1, location.y - 65);
            rect(location.x + 40* -1, location.y - 80, location.x + 60* -1, location.y - 70);
            rect(location.x + 45* -1, location.y - 70, location.x + 60* -1, location.y - 65);

            fill(#f0ff00);
            rect(location.x + 50* -1, location.y - 70, location.x + 60* -1, location.y - 65);
            rect(location.x + 55* -1, location.y - 65, location.x + 60* -1, location.y - 60);
            rect(location.x + 55* -1, location.y - 55, location.x + 60* -1, location.y - 50);
          }
        }
      }
    }
  }
}
class drawBackground
{
  void display()
  {
    background(#122c45);
    fill(#2d2d2d);
    rect(0, 350, 400, 400);
    fill(#838383);
    for (int i = 0; i < 12; i += 1) {
      rect((i*40), 355, 30+(i*40), 370);
      rect((i*40)-20, 375, 30+(i*40)-20, 390);
      rect((i*40), 395, 30+(i*40), 410);
    }
    fill(#434343);
    rect(150, 310, 250, 350);
  }
}
class Enemy
{
  PVector Position;
  boolean moveLeft;
  boolean Dead;
  int facingLeft;
  float movementSpeed;
  float Health;
  float slashDamage;
  float knockBackDistance;

  Enemy() {
    Position = new PVector (300, 350);
    moveLeft = true;
    facingLeft = -1;
    movementSpeed = 1;
    Health = 50;
    slashDamage = 5;
    knockBackDistance = 50;
  }


  // If the shadow is in range of the slash animation then knock him back and damage him
  void knockback() {
    
    if (keyPressed) {
      if (key == 'k') {
        if ((Knight.facingRight == 1) && ((Position.x > Knight.location.x) && (Position.x < Knight.location.x + 130) && (Knight.Alive))) {
          Position.x += knockBackDistance;
          Health -= slashDamage;
        }
        if ((Knight.facingRight == 0) && ((Position.x < Knight.location.x) && (Position.x > Knight.location.x - 130) && (Knight.Alive))) {
          Position.x -= knockBackDistance;
          Health -= slashDamage;
        }
      }
      // If the player is blocking stun the shadow if he is in range of the shield until the player moves
      //println((key == 'j'), (Knight.facingRight == 0), (Position.x < Knight.location.x), (Position.x > Knight.location.x - 90));
      if (((key == 'j') && (Knight.facingRight == 1) && (Position.x > Knight.location.x) && (Position.x < Knight.location.x + 90))) 
      {
        movementSpeed = 0;
      }
      else if (((key == 'j') && (Knight.facingRight == 0) && (Position.x < Knight.location.x) && (Position.x > Knight.location.x - 130))) 
      {
        movementSpeed = 0;
      } else
      {
        movementSpeed = 1;
      }
    }
  }

  void healthBar() {
    if (Health < 1)
    {
      Health = 1;
      Dead = true;
    }
    if (!Dead){
    fill(255);
    rect(Position.x-20, Position.y - 150, Position.x-20 + Health, Position.y - 140);
  }
  }



  void Movement() {
    if (Position.x > Knight.location.x) {
      Position.x -= movementSpeed;
      facingLeft = -1;
    } else if (Position.x < Knight.location.x) {
      Position.x += movementSpeed;
      facingLeft = 1;
    }
  }

  void Display() {
    if (moveLeft == true) {
      if (!Dead)
      {
        
        fill(0);
        noStroke();
        //head
        rect(Position.x - 5 * facingLeft, Position.y - 125, Position.x + 15 * facingLeft, Position.y - 120);
        rect(Position.x - 10 * facingLeft, Position.y - 120, Position.x + 15 * facingLeft, Position.y - 115);
        rect(Position.x - 15 * facingLeft, Position.y - 115, Position.x + 25 * facingLeft, Position.y - 110);  
        rect(Position.x - 20 * facingLeft, Position.y - 110, Position.x + 25 * facingLeft, Position.y - 90);
        rect(Position.x - 20 * facingLeft, Position.y - 100, Position.x + 25 * facingLeft, Position.y - 75);
        rect(Position.x - 20 * facingLeft, Position.y - 90, Position.x + 20 * facingLeft, Position.y - 70);


        rect(Position.x - 5 * facingLeft, Position.y - 120, Position.x + 10 * facingLeft, Position.y - 115);

        rect(Position.x + 5 * facingLeft, Position.y - 120, Position.x + 10 * facingLeft, Position.y - 115);
        rect(Position.x - 10 * facingLeft, Position.y - 115, Position.x, Position.y - 110);
        rect(Position.x - 15 * facingLeft, Position.y - 110, Position.x- 5 * facingLeft, Position.y - 100);
        rect(Position.x - 15 * facingLeft, Position.y - 100, Position.x- 10 * facingLeft, Position.y - 95);
        rect(Position.x, Position.y - 110, Position.x + 5 * facingLeft, Position.y - 100);
        rect(Position.x + 5 * facingLeft, Position.y - 110, Position.x + 15 * facingLeft, Position.y - 105);
        rect(Position.x + 10 * facingLeft, Position.y - 115, Position.x + 15 * facingLeft, Position.y - 105);
        rect(Position.x + 20 * facingLeft, Position.y - 105, Position.x + 25 * facingLeft, Position.y - 110);


        rect(Position.x - 15 * facingLeft, Position.y - 95, Position.x - 10 * facingLeft, Position.y - 75);
        rect(Position.x - 10 * facingLeft, Position.y - 100, Position.x - 5 * facingLeft, Position.y - 95);
        rect(Position.x - 5 * facingLeft, Position.y - 95, Position.x + 25 * facingLeft, Position.y - 90);
        rect(Position.x, Position.y - 100, Position.x + 5 * facingLeft, Position.y - 95);
        rect(Position.x + 10 * facingLeft, Position.y - 105, Position.x + 15 * facingLeft, Position.y - 95);
        rect(Position.x + 20 * facingLeft, Position.y - 105, Position.x + 25 * facingLeft, Position.y - 95);

        rect(Position.x - 5 * facingLeft, Position.y - 85, Position.x + 20 * facingLeft, Position.y - 80);
        rect(Position.x, Position.y - 80, Position.x + 20 * facingLeft, Position.y - 75);

        //body

        rect(Position.x - 15 * facingLeft, Position.y - 70, Position.x + 25 * facingLeft, Position.y - 25);
        rect(Position.x - 10 * facingLeft, Position.y - 25, Position.x + 20 * facingLeft, Position.y - 20);

        rect(Position.x - 10 * facingLeft, Position.y - 70, Position.x + 20 * facingLeft, Position.y - 25);

        rect(Position.x - 10 * facingLeft, Position.y - 65, Position.x + 10 * facingLeft, Position.y - 25);
        rect(Position.x - 10 * facingLeft, Position.y - 60, Position.x + 20 * facingLeft, Position.y - 25);

        //legs

        rect(Position.x - 10 * facingLeft, Position.y - 20, Position.x - 5 * facingLeft, Position.y - 5);
        rect(Position.x - 15 * facingLeft, Position.y - 10, Position.x - 5 * facingLeft, Position.y - 5);
        rect(Position.x - 15 * facingLeft, Position.y - 10, Position.x - 10 * facingLeft, Position.y - 0);
        rect(Position.x + 20 * facingLeft, Position.y - 25, Position.x + 25 * facingLeft, Position.y - 0);

        //right arm

        rect(Position.x - 25 * facingLeft, Position.y - 70, Position.x, Position.y - 55);
        rect(Position.x - 30 * facingLeft, Position.y - 65, Position.x - 5 * facingLeft, Position.y - 50);
        rect(Position.x - 35 * facingLeft, Position.y - 50, Position.x - 15 * facingLeft, Position.y - 40);
        rect(Position.x - 40 * facingLeft, Position.y - 40, Position.x - 20 * facingLeft, Position.y - 25);


        rect(Position.x - 15 * facingLeft, Position.y - 70, Position.x - 5 * facingLeft, Position.y - 60);
        rect(Position.x - 25 * facingLeft, Position.y - 65, Position.x - 10 * facingLeft, Position.y - 55);  
        rect(Position.x - 30 * facingLeft, Position.y - 50, Position.x - 15 * facingLeft, Position.y - 45);
        rect(Position.x - 30 * facingLeft, Position.y - 45, Position.x - 20 * facingLeft, Position.y - 40);


        rect(Position.x - 15 * facingLeft, Position.y - 70, Position.x - 5 * facingLeft, Position.y - 65);
        rect(Position.x - 25 * facingLeft, Position.y - 65, Position.x - 15 * facingLeft, Position.y - 60);
        rect(Position.x - 35 * facingLeft, Position.y - 40, Position.x - 25 * facingLeft, Position.y - 30);


        rect(Position.x - 15 * facingLeft, Position.y - 70, Position.x - 10 * facingLeft, Position.y - 65);
        rect(Position.x - 25 * facingLeft, Position.y - 65, Position.x - 20 * facingLeft, Position.y - 60);

        rect(Position.x - 35 * facingLeft, Position.y - 40, Position.x - 30 * facingLeft, Position.y - 35);


        //left arm

        rect(Position.x + 25 * facingLeft, Position.y - 75, Position.x + 35 * facingLeft, Position.y - 50);
        rect(Position.x + 35 * facingLeft, Position.y - 70, Position.x + 40 * facingLeft, Position.y - 55);


        rect(Position.x + 30 * facingLeft, Position.y - 70, Position.x + 35 * facingLeft, Position.y - 55);


        rect(Position.x + 30 * facingLeft, Position.y - 70, Position.x + 35 * facingLeft, Position.y - 65);

        //sword

        rect(Position.x - 30 * facingLeft, Position.y - 40, Position.x - 20 * facingLeft, Position.y - 20);
        rect(Position.x - 20 * facingLeft, Position.y - 40, Position.x - 10 * facingLeft, Position.y - 25);
        rect(Position.x - 1 * facingLeft, Position.y - 45, Position.x, Position.y - 30);
        rect(Position.x, Position.y - 50, Position.x + 15 * facingLeft, Position.y - 35);
        rect(Position.x + 15 * facingLeft, Position.y - 55, Position.x + 30 * facingLeft, Position.y - 40);

        rect(Position.x - 25 * facingLeft, Position.y - 35, Position.x - 20 * facingLeft, Position.y - 25);
        rect(Position.x - 20 * facingLeft, Position.y - 35, Position.x - 10 * facingLeft, Position.y - 30);   
        rect(Position.x - 10 * facingLeft, Position.y - 40, Position.x, Position.y - 35);
        rect(Position.x, Position.y - 45, Position.x + 15 * facingLeft, Position.y - 40);
        rect(Position.x + 15 * facingLeft, Position.y - 50, Position.x + 30 * facingLeft, Position.y - 45);
      }
    }
    {
    }
  }
}


class Platform
{

  PVector location;
  boolean grounded;
  float ground;

  float left, top, right, bottom;
  


  Platform(float tempLeft, float tempTop, float tempRight, float tempBottom)
  {
    left=tempLeft;
    top=tempTop;
    right=tempRight;
    bottom=tempBottom;
  }


  void display()
  {
    noStroke();
    fill(100);
    rect(left, top, right, bottom);
  }


}