Class Entity
java.lang.Object
fr.paris.saclay.sidescroller.drawables.Drawable
fr.paris.saclay.sidescroller.drawables.entities.Entity
Template for each moving entity (player or enemy).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final HashMap<Direction,
List<BufferedImage>> Links the Direction the entity is facing to the list of images that represent the entity in that direction.protected Rectangle
Represents the area of the entity that is used to compute collisions with enemies or projectiles.protected Dimension
Hitbox size of attack action.protected Rectangle
Represents the area of the entity that is used to compute blocks with enemies or projectiles.protected Dimension
Hitbox size of block action.protected Rectangle
Represents the area of the entity that is used to compute collisions with enemies or projectiles.protected int
We decided to make every hitbox square.protected BufferedImage
Final image that is shown during the rendering of the entity.protected int
Number of frames during which the player will stay invincible.protected boolean
True if entity is currently attacking.protected boolean
True if entity is currently blocking.protected boolean
True when entity's life points reach 0.protected boolean
True if entity is currently invincible.protected boolean
Is true when the entity is jumping, therefore blocking any other type of movement.protected int
The number of the life points that the entity currently has.protected int
Maximum invincibility timer.protected int
Maximum life points.protected int
Identifies the number of frames that have to be rendered before changing a sprite (during an animation).protected int
Identifies the sprite that is currently being rendered -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
This method makes the entity chase the player on the X axis until its hitbox collides with the one of the player.void
draw
(Graphics2D graphics2D) Entities present a default version of thedraw()
method.protected void
drawHpBar
(Graphics2D graphics2D) Draws enemies life points on top of them: green bar with red chunks for each lost life point.Gets attack hit box.Gets block hit box.Gets hit box.int
Gets life points.int
Gets maximum invincibility.int
Gets maximum life points.boolean
Is attacking boolean.boolean
Is blocking boolean.boolean
isDead()
Is dead boolean.boolean
Is invincible boolean.boolean
Is jumping boolean.void
setAttacking
(boolean isAttacking) Sets attacking.protected void
setAttackSprites
(List<String> paths) Adds provided attack sprites to animation map.protected void
setBlockSprites
(List<String> paths) Adds provided block sprites to animation map.void
setDead
(boolean dead) Sets dead.void
setEntityInvincible
(int invincibilityTimer) Sets entity invincible.protected void
setJumpSprites
(List<String> paths) Adds provided jump sprites to animation map.protected void
setSprites
(List<String> paths) Adds provided walk sprites to animation map.void
Decreases life points if the entity reaches damage.protected void
Defines unique movement for each entity, currently implemented in enemies.void
update()
Defines actions for each frame: chasePlayer: tracks players movement and defines the shortest path to it.protected void
Updates the position of the entity's hitbox according to the entity's position inside the screen.protected void
Entities present a default version of theupdateSprites()
method.Methods inherited from class fr.paris.saclay.sidescroller.drawables.Drawable
getXPosition, updatePositionToCamera
-
Field Details
-
animationMap
Links the Direction the entity is facing to the list of images that represent the entity in that direction. -
lifePoints
protected int lifePointsThe number of the life points that the entity currently has. -
spriteCounter
protected int spriteCounterIdentifies the number of frames that have to be rendered before changing a sprite (during an animation). -
isDead
protected boolean isDeadTrue when entity's life points reach 0. -
spriteNumber
protected int spriteNumberIdentifies the sprite that is currently being rendered -
isJumping
protected boolean isJumpingIs true when the entity is jumping, therefore blocking any other type of movement. -
maximumLifePoints
protected int maximumLifePointsMaximum life points. -
image
Final image that is shown during the rendering of the entity. -
hitboxSize
protected int hitboxSizeWe decided to make every hitbox square. Therefore, this number indicates both the height and the width of the hitbox square (in pixels). -
attackHitboxSize
Hitbox size of attack action. -
blockHitboxSize
Hitbox size of block action. -
hitBox
Represents the area of the entity that is used to compute collisions with enemies or projectiles. -
attackHitBox
Represents the area of the entity that is used to compute collisions with enemies or projectiles. -
blockHitBox
Represents the area of the entity that is used to compute blocks with enemies or projectiles. -
isInvincible
protected boolean isInvincibleTrue if entity is currently invincible. -
invincibilityTimer
protected int invincibilityTimerNumber of frames during which the player will stay invincible. -
maximumInvincibility
protected int maximumInvincibilityMaximum invincibility timer. -
isAttacking
protected boolean isAttackingTrue if entity is currently attacking. -
isBlocking
protected boolean isBlockingTrue if entity is currently blocking.
-
-
Constructor Details
-
Entity
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
Adds provided walk sprites to animation map.- Parameters:
paths
- sprites.
-
setJumpSprites
Adds provided jump sprites to animation map.- Parameters:
paths
- sprites.
-
setAttackSprites
Adds provided attack sprites to animation map.- Parameters:
paths
- sprites.
-
setBlockSprites
Adds provided block sprites to animation map.- Parameters:
paths
- sprites.
-
getLifePoints
public int getLifePoints()Gets life points.- Returns:
- the life points
-
getHitBox
Gets hit box.- Returns:
- the hit box
-
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
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.
-
draw
Entities present a default version of thedraw()
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 toOverride
if you want to implement more fancy stuff. -
isInvincible
public boolean isInvincible()Is invincible boolean.- Returns:
- the boolean
-
drawHpBar
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 theupdateSprites()
method. Each sprite only lasts for 5 frames before changing to the next one. Feel free toOverride
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
-