Class Entity

java.lang.Object
dev.kyzel.game.entity.Entity
All Implemented Interfaces:
IAttackable
Direct Known Subclasses:
Animal, Player

public abstract class Entity extends Object implements IAttackable
A class to handle Entity in the game.
  • Field Details

    • maxHealingCounter

      public static final int maxHealingCounter
      Constant for the max value of healing counter.
      See Also:
    • maxHitTick

      public static final int maxHitTick
      Constant for the max value of hit cooldown.
      See Also:
    • maxKnockbackCounter

      public static final int maxKnockbackCounter
      Constant for the max value of knockback counter.
      See Also:
    • maxInvincibleCounter

      public static final int maxInvincibleCounter
      Constant for the max value of invincible counter.
      See Also:
    • render

      protected Renderer render
      The Renderer where the entity will be drawn on.
    • game

      protected Game game
      The Game where the entity interacts.
    • direction

      protected Direction direction
      The Direction the entity moves in.
    • previousDirection

      protected Direction previousDirection
      The last Direction of the entity.
    • state

      protected EntityState state
      The EntityState of the entity.
    • x

      protected int x
      The x coordinate of the entity.
    • y

      protected int y
      The y coordinate of the entity.
    • maxHealthValue

      protected int maxHealthValue
      The max health value of the entity.
    • currentHealthValue

      protected int currentHealthValue
      The current health value of the entity.
    • attackValue

      protected int attackValue
      The attack damage value of the entity.
    • speed

      protected int speed
      The speed of the entity.
    • basedSpeed

      protected int basedSpeed
      The based speed of the entity.
    • isCursed

      protected boolean isCursed
      A variable to see if the entity is cursed.
    • solidArea

      protected Rectangle solidArea
      The hitbox of the entity.
    • solidAreaDefaultX

      protected int solidAreaDefaultX
      The default x coordinate of the hitbox.
    • solidAreaDefaultY

      protected int solidAreaDefaultY
      The default y coordinate of the hitbox.
    • spriteCounter

      protected int spriteCounter
      The sprite counter, which is used for the animation
    • healingCounter

      protected int healingCounter
      The default healing counter.
    • hitTick

      protected int hitTick
      The default hit cooldown.
    • knockbackCounter

      protected int knockbackCounter
      The default knockback counter;
    • invincibleCounter

      protected int invincibleCounter
      The default invincible counter.
  • Constructor Details

    • Entity

      public Entity(Renderer render, Game game, int x, int y, int speed)
      Creates a new Entity. Construction of a new, plain Entity is not allowed. Construction has to be explicitly typed (e.g. Player, Slime,...).
      Parameters:
      render - the Renderer where the entity will be drawn on
      game - the Game where the entity interacts
      x - the x coordinate
      y - the y coordinate
      speed - the speed of the entity
  • Method Details

    • isInRange

      public boolean isInRange(Tile[][] tileMap, int x, int y)
      Checks if the entity is inside the map.
      Parameters:
      tileMap - the map
      x - the x coordinate
      y - the y coordinate
      Returns:
      if the entity is inside the map
    • update

      public void update()
      Updates the entity.
    • initTexture

      public abstract void initTexture()
      Initializes the base texture.
    • inflictDamage

      public void inflictDamage(Entity target)
      Description copied from interface: IAttackable
      Inflicts damage on the given target.
      Specified by:
      inflictDamage in interface IAttackable
      Parameters:
      target - the given target
    • knockback

      public void knockback()
      Inflicts knockback on the entity.
    • healing

      public void healing()
      Heals the entity if the requirements are met.
    • cursed

      public void cursed()
      Curses the entity.
    • isAlive

      public boolean isAlive()
      Checks if the entity is alive.
      Returns:
      if the entity is alive
    • isDead

      public boolean isDead()
      Checks if the entity is dead.
      Returns:
      if the entity is dead
    • collideWithTile

      public boolean collideWithTile(Tile[][] tileMap)
      Checks if the entity collides with any solid tile.
      Parameters:
      tileMap - the map
      Returns:
      if the entity collides with any solid tile
    • collideWithPlayer

      public boolean collideWithPlayer()
      Checks if the entity collides with the player.
      Returns:
      if the entity collides with the player.
    • collideWithEntity

      public int collideWithEntity(ArrayList<Entity> targetList, Direction currentEntityDirection)
      Checks if the entity collides with any other entity in the given list.
      Parameters:
      targetList - the list of all the target entities
      currentEntityDirection - the current Direction of the entity
      Returns:
      the index of the entity in the list if the entity collides to any other entity, -1 otherwise
    • increaseImageIndex

      public int increaseImageIndex(int currentIndex, int maxIndex)
      Increases the image index so that it will always be in range.
      Parameters:
      currentIndex - the current index
      maxIndex - the max index
      Returns:
      the new index
    • getRender

      public Renderer getRender()
      Gets the Renderer where the entity will be drawn on.
      Returns:
      the Renderer where the entity will be drawn on
    • setRender

      public void setRender(Renderer render)
      Set the Renderer where the entity will be drawn on.
      Parameters:
      render - the Renderer where the entity will be drawn on
    • getGame

      public Game getGame()
      Gets the Game where the entity interacts.
      Returns:
      the Game where the entity interacts
    • getX

      public int getX()
      Gets the x coordinate of the entity.
      Returns:
      the x coordinate of the entity
    • setX

      public void setX(int x)
      Set the x coordinate of the entity to the given value.
      Parameters:
      x - the given value
    • getY

      public int getY()
      Gets the y coordinate of the entity.
      Returns:
      the y coordinate of the entity
    • setY

      public void setY(int y)
      Set the y coordinate of the entity to the given value.
      Parameters:
      y - the given value
    • getSolidArea

      public Rectangle getSolidArea()
      Gets the hitbox of the entity.
      Returns:
      the hitbox of the entity
    • getSolidAreaDefaultX

      public int getSolidAreaDefaultX()
      Gets the default x coordinate of the hitbox.
      Returns:
      the default x coordinate of the hitbox
    • getSolidAreaDefaultY

      public int getSolidAreaDefaultY()
      Gets the default y coordinate of the hitbox.
      Returns:
      the default y coordinate of the hitbox
    • getDirection

      public Direction getDirection()
      Gets the current Direction of the entity.
      Returns:
      the current Direction of the entity
    • setDirection

      public void setDirection(Direction dir)
      Set the current Direction of the entity to the given value.
      Parameters:
      dir - the given value
    • getPreviousDirection

      public Direction getPreviousDirection()
      Gets the previous direction of the entity.
      Returns:
      the previous direction of the entity
    • setPreviousDirection

      public void setPreviousDirection(Direction previousDirection)
      Set the previous direction of the entity to the given value.
      Parameters:
      previousDirection - the given value
    • setAttackValue

      public void setAttackValue(int value)
      Description copied from interface: IAttackable
      Set the attack value of the entity to the given value.
      Specified by:
      setAttackValue in interface IAttackable
      Parameters:
      value - the given value
    • getAttackValue

      public int getAttackValue()
      Description copied from interface: IAttackable
      Gets the attack value of the entity.
      Specified by:
      getAttackValue in interface IAttackable
      Returns:
      the attack value of the entity
    • setHealthValue

      public void setHealthValue(int value)
      Description copied from interface: IAttackable
      Set the current health value of the entity to the given value.
      Specified by:
      setHealthValue in interface IAttackable
      Parameters:
      value - the given value
    • getHealthValue

      public int getHealthValue()
      Description copied from interface: IAttackable
      Gets the current health value of the entity.
      Specified by:
      getHealthValue in interface IAttackable
      Returns:
      the current health value of the entity
    • setMaxHealthValue

      public void setMaxHealthValue(int value)
      Description copied from interface: IAttackable
      Set the max health value of the entity to the given value.
      Specified by:
      setMaxHealthValue in interface IAttackable
      Parameters:
      value - the given value
    • getMaxHealthValue

      public int getMaxHealthValue()
      Description copied from interface: IAttackable
      Gets the max health value of the entity.
      Specified by:
      getMaxHealthValue in interface IAttackable
      Returns:
      the max health value of the entity
    • getSpeed

      public int getSpeed()
      Gets the speed of the entity.
      Returns:
      the speed of the entity
    • setSpeed

      public void setSpeed(int speed)
      Set the speed of the entity to the given value.
      Parameters:
      speed - the given value
    • getSwimmingSpeed

      public int getSwimmingSpeed()
      Gets the speed of the entity when swimming.
      Returns:
      the speed of the entity when swimming
    • isCursed

      public boolean isCursed()
      Checks if the entity is cursed.
      Returns:
      if the entity is cursed.
    • getKnockbackCounter

      public int getKnockbackCounter()
      Gets the current knockback counter of the entity.
      Returns:
      the current knockback counter of the entity
    • setKnockbackCounter

      public void setKnockbackCounter(int counter)
      Set the current knockback counter to the given value.
      Parameters:
      counter - the given value
    • getInvincibleCounter

      public int getInvincibleCounter()
      Gets the current invincible counter of the entity.
      Returns:
      the current invincible counter
    • setInvincibleCounter

      public void setInvincibleCounter(int counter)
      Set the current invincible counter of the entity to the given value.
      Parameters:
      counter - the given value
    • drawHealthBar

      public abstract void drawHealthBar(Graphics g)
      Draws the health bar of the entity.
      Parameters:
      g - the Graphics which is used to draw
    • draw

      public abstract void draw(Graphics g)
      Draws the entity.
      Parameters:
      g - the Graphics which is used to draw