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 RectangleRepresents the area of the entity that is used to compute collisions with enemies or projectiles.protected DimensionHitbox size of attack action.protected RectangleRepresents the area of the entity that is used to compute blocks with enemies or projectiles.protected DimensionHitbox size of block action.protected RectangleRepresents the area of the entity that is used to compute collisions with enemies or projectiles.protected intWe decided to make every hitbox square.protected BufferedImageFinal image that is shown during the rendering of the entity.protected intNumber of frames during which the player will stay invincible.protected booleanTrue if entity is currently attacking.protected booleanTrue if entity is currently blocking.protected booleanTrue when entity's life points reach 0.protected booleanTrue if entity is currently invincible.protected booleanIs true when the entity is jumping, therefore blocking any other type of movement.protected intThe number of the life points that the entity currently has.protected intMaximum invincibility timer.protected intMaximum life points.protected intIdentifies the number of frames that have to be rendered before changing a sprite (during an animation).protected intIdentifies the sprite that is currently being rendered -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidThis method makes the entity chase the player on the X axis until its hitbox collides with the one of the player.voiddraw(Graphics2D graphics2D) Entities present a default version of thedraw()method.protected voiddrawHpBar(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.intGets life points.intGets maximum invincibility.intGets maximum life points.booleanIs attacking boolean.booleanIs blocking boolean.booleanisDead()Is dead boolean.booleanIs invincible boolean.booleanIs jumping boolean.voidsetAttacking(boolean isAttacking) Sets attacking.protected voidsetAttackSprites(List<String> paths) Adds provided attack sprites to animation map.protected voidsetBlockSprites(List<String> paths) Adds provided block sprites to animation map.voidsetDead(boolean dead) Sets dead.voidsetEntityInvincible(int invincibilityTimer) Sets entity invincible.protected voidsetJumpSprites(List<String> paths) Adds provided jump sprites to animation map.protected voidsetSprites(List<String> paths) Adds provided walk sprites to animation map.voidDecreases life points if the entity reaches damage.protected voidDefines unique movement for each entity, currently implemented in enemies.voidupdate()Defines actions for each frame: chasePlayer: tracks players movement and defines the shortest path to it.protected voidUpdates the position of the entity's hitbox according to the entity's position inside the screen.protected voidEntities 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 toOverrideif 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 toOverrideif 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
-