java.lang.Object
fr.paris.saclay.sidescroller.drawables.Drawable
fr.paris.saclay.sidescroller.drawables.entities.Entity
Direct Known Subclasses:
Bat, Ghost, Player

public abstract class Entity extends Drawable
Template for each moving entity (player or enemy).
  • Field Details

    • animationMap

      protected final HashMap<Direction,List<BufferedImage>> animationMap
      Links the Direction the entity is facing to the list of images that represent the entity in that direction.
    • lifePoints

      protected int lifePoints
      The number of the life points that the entity currently has.
    • spriteCounter

      protected int spriteCounter
      Identifies the number of frames that have to be rendered before changing a sprite (during an animation).
    • isDead

      protected boolean isDead
      True when entity's life points reach 0.
    • spriteNumber

      protected int spriteNumber
      Identifies the sprite that is currently being rendered
    • isJumping

      protected boolean isJumping
      Is true when the entity is jumping, therefore blocking any other type of movement.
    • maximumLifePoints

      protected int maximumLifePoints
      Maximum life points.
    • image

      protected BufferedImage image
      Final image that is shown during the rendering of the entity.
    • hitboxSize

      protected int hitboxSize
      We decided to make every hitbox square. Therefore, this number indicates both the height and the width of the hitbox square (in pixels).
    • attackHitboxSize

      protected Dimension attackHitboxSize
      Hitbox size of attack action.
    • blockHitboxSize

      protected Dimension blockHitboxSize
      Hitbox size of block action.
    • hitBox

      protected Rectangle hitBox
      Represents the area of the entity that is used to compute collisions with enemies or projectiles.
    • attackHitBox

      protected Rectangle attackHitBox
      Represents the area of the entity that is used to compute collisions with enemies or projectiles.
    • blockHitBox

      protected Rectangle blockHitBox
      Represents the area of the entity that is used to compute blocks with enemies or projectiles.
    • isInvincible

      protected boolean isInvincible
      True if entity is currently invincible.
    • invincibilityTimer

      protected int invincibilityTimer
      Number of frames during which the player will stay invincible.
    • maximumInvincibility

      protected int maximumInvincibility
      Maximum invincibility timer.
    • isAttacking

      protected boolean isAttacking
      True if entity is currently attacking.
    • isBlocking

      protected boolean isBlocking
      True if entity is currently blocking.
  • Constructor Details

    • Entity

      public Entity(GamePanel gamePanel)
      Creates an Entity instance passing down GamePanel reference.
      Parameters:
      gamePanel - reference.
  • Method Details

    • updateHitboxPosition

      protected void updateHitboxPosition()
      Updates the position of the entity's hitbox according to the entity's position inside the screen.
    • tookDamage

      public void tookDamage()
      Decreases life points if the entity reaches damage.
    • setSprites

      protected void setSprites(List<String> paths)
      Adds provided walk sprites to animation map.
      Parameters:
      paths - sprites.
    • setJumpSprites

      protected void setJumpSprites(List<String> paths)
      Adds provided jump sprites to animation map.
      Parameters:
      paths - sprites.
    • setAttackSprites

      protected void setAttackSprites(List<String> paths)
      Adds provided attack sprites to animation map.
      Parameters:
      paths - sprites.
    • setBlockSprites

      protected void setBlockSprites(List<String> paths)
      Adds provided block sprites to animation map.
      Parameters:
      paths - sprites.
    • getLifePoints

      public int getLifePoints()
      Gets life points.
      Returns:
      the life points
    • getHitBox

      public Rectangle getHitBox()
      Gets hit box.
      Returns:
      the hit box
    • getBlockHitBox

      public Rectangle getBlockHitBox()
      Gets block hit box.
      Returns:
      the block hit box
    • setEntityInvincible

      public void setEntityInvincible(int invincibilityTimer)
      Sets entity invincible.
      Parameters:
      invincibilityTimer - the invincibility timer
    • getMaximumInvincibility

      public int getMaximumInvincibility()
      Gets maximum invincibility.
      Returns:
      the maximum invincibility
    • isAttacking

      public boolean isAttacking()
      Is attacking boolean.
      Returns:
      the boolean
    • setAttacking

      public void setAttacking(boolean isAttacking)
      Sets attacking.
      Parameters:
      isAttacking - the is attacking
    • getAttackHitBox

      public Rectangle getAttackHitBox()
      Gets attack hit box.
      Returns:
      the attack hit box
    • getMaximumLifePoints

      public int getMaximumLifePoints()
      Gets maximum life points.
      Returns:
      the maximum life points
    • isDead

      public boolean isDead()
      Is dead boolean.
      Returns:
      the boolean
    • setDead

      public void setDead(boolean dead)
      Sets dead.
      Parameters:
      dead - the dead
    • update

      public void update()
      Defines actions for each frame:
      • chasePlayer: tracks players movement and defines the shortest path to it.
      • uniqueMovement: implements unique movement if entity requires it.
      • updateHitboxPosition: tracks entity movement and updates hitbox.
      Specified by:
      update in class Drawable
    • draw

      public void draw(Graphics2D graphics2D)
      Entities present a default version of the draw() method. This method only supports basic sprite animations, namely when moving to the left and right directions (jump, up-left and up-right are not supported). Feel free to Override if you want to implement more fancy stuff.
      Specified by:
      draw in class Drawable
      Parameters:
      graphics2D - the rendering environment.
    • isInvincible

      public boolean isInvincible()
      Is invincible boolean.
      Returns:
      the boolean
    • drawHpBar

      protected void drawHpBar(Graphics2D graphics2D)
      Draws enemies life points on top of them: green bar with red chunks for each lost life point.
      Parameters:
      graphics2D - the rendering component.
    • chasePlayer

      protected void chasePlayer()
      This method makes the entity chase the player on the X axis until its hitbox collides with the one of the player.
    • uniqueMovement

      protected void uniqueMovement()
      Defines unique movement for each entity, currently implemented in enemies.
    • updateSprites

      protected void updateSprites()
      Entities present a default version of the updateSprites() method. Each sprite only lasts for 5 frames before changing to the next one. Feel free to Override if you want to implement more fancy stuff.
    • isBlocking

      public boolean isBlocking()
      Is blocking boolean.
      Returns:
      the boolean
    • isJumping

      public boolean isJumping()
      Is jumping boolean.
      Returns:
      the boolean