Class Player

java.lang.Object
dev.kyzel.game.entity.Entity
dev.kyzel.game.entity.Player
All Implemented Interfaces:
IAttackable

public class Player extends Entity
The player class.
  • Field Details

    • imageIndex

      private int imageIndex
      The current index to use as the player's sprite.
    • playerImage

      private BufferedImage playerImage
      The current player's sprite.
    • isSwimming

      private boolean isSwimming
      A variable to see if the player is swimming.
    • isLeftLeg

      private boolean isLeftLeg
      A variable to help with the animation.
    • currentLevel

      private int currentLevel
      The current level of the player.
    • score

      private int score
      The current score of the player at the current level.
    • maxScoreMultiplier

      private final int maxScoreMultiplier
      The max score multiplier.
      See Also:
  • Constructor Details

    • Player

      public Player(Renderer render, Game game, int x, int y, int speed)
      Creates a new Player.
      Parameters:
      render - the Renderer where the player will be drawn on
      game - the Game where the player interacts
      x - the x coordinate
      y - the y coordinate
      speed - the speed of the player
  • Method Details

    • initTexture

      public void initTexture()
      Description copied from class: Entity
      Initializes the base texture.
      Specified by:
      initTexture in class Entity
    • checkSwimming

      private void checkSwimming()
      Checks if the player is swimming.
    • scoreUp

      private void scoreUp(Animal target)
      Increases the player's score up with the points taken from the target.
      Parameters:
      target - the target
    • attack

      private void attack(int collidedEntity)
      Attempts to attack something.
      Parameters:
      collidedEntity - the collided entity, -1 represents that there is no collided entity
    • update

      public void update()
      Description copied from class: Entity
      Updates the entity.
      Overrides:
      update in class Entity
    • getPlayerImage

      public BufferedImage getPlayerImage()
      Gets the current player's sprite.
      Returns:
      the current player's sprite
    • getScore

      public int getScore()
      Gets the current score of the player.
      Returns:
      the current score of the player
    • getCurrentLevel

      public int getCurrentLevel()
      Gets the current level of the player.
      Returns:
      the current level of the player
    • setCurrentPlayerImage

      public void setCurrentPlayerImage(Direction playerDir)
      Set the player's sprite and handles animation in the given Direction.
      Parameters:
      playerDir - the given Direction
    • drawStatusBar

      public void drawStatusBar(Graphics g, Color color, int value, int maxValue, int barIndex)
      Draws a scalable value bar for the player.
      Parameters:
      g - the Graphics which is used to draw
      color - the color of the bar
      value - the current value
      maxValue - the max value
      barIndex - the index of the bar, which is used to determine the order of the bar
    • drawHealthBar

      public void drawHealthBar(Graphics g)
      Description copied from class: Entity
      Draws the health bar of the entity.
      Specified by:
      drawHealthBar in class Entity
      Parameters:
      g - the Graphics which is used to draw
    • drawScoreBar

      public void drawScoreBar(Graphics g)
      Draws the player's score/exp.
      Parameters:
      g - the Graphics which is used to draw
    • drawHitCooldownBar

      public void drawHitCooldownBar(Graphics g)
      Draws the player's hit cooldown.
      Parameters:
      g - the Graphics which is used to draw
    • draw

      public void draw(Graphics g)
      Description copied from class: Entity
      Draws the entity.
      Specified by:
      draw in class Entity
      Parameters:
      g - the Graphics which is used to draw