Package dev.kyzel.game.entity
Class Entity
java.lang.Object
dev.kyzel.game.entity.Entity
- All Implemented Interfaces:
IAttackable
A class to handle Entity in the game.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe attack damage value of the entity.protected intThe based speed of the entity.protected intThe current health value of the entity.protected DirectionTheDirectionthe entity moves in.protected GameTheGamewhere the entity interacts.protected intThe default healing counter.protected intThe default hit cooldown.protected intThe default invincible counter.protected booleanA variable to see if the entity is cursed.protected intThe default knockback counter;static final intConstant for the max value of healing counter.protected intThe max health value of the entity.static final intConstant for the max value of hit cooldown.static final intConstant for the max value of invincible counter.static final intConstant for the max value of knockback counter.protected DirectionThe lastDirectionof the entity.protected RendererTheRendererwhere the entity will be drawn on.protected RectangleThe hitbox of the entity.protected intThe default x coordinate of the hitbox.protected intThe default y coordinate of the hitbox.protected intThe speed of the entity.protected intThe sprite counter, which is used for the animationprotected EntityStateTheEntityStateof the entity.protected intThe x coordinate of the entity.protected intThe y coordinate of the entity. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcollideWithEntity(ArrayList<Entity> targetList, Direction currentEntityDirection) Checks if the entity collides with any other entity in the given list.booleanChecks if the entity collides with the player.booleancollideWithTile(Tile[][] tileMap) Checks if the entity collides with any solid tile.voidcursed()Curses the entity.abstract voidDraws the entity.abstract voidDraws the health bar of the entity.intGets the attack value of the entity.Gets the currentDirectionof the entity.getGame()Gets theGamewhere the entity interacts.intGets the current health value of the entity.intGets the current invincible counter of the entity.intGets the current knockback counter of the entity.intGets the max health value of the entity.Gets the previous direction of the entity.Gets theRendererwhere the entity will be drawn on.Gets the hitbox of the entity.intGets the default x coordinate of the hitbox.intGets the default y coordinate of the hitbox.intgetSpeed()Gets the speed of the entity.intGets the speed of the entity when swimming.intgetX()Gets the x coordinate of the entity.intgetY()Gets the y coordinate of the entity.voidhealing()Heals the entity if the requirements are met.intincreaseImageIndex(int currentIndex, int maxIndex) Increases the image index so that it will always be in range.voidinflictDamage(Entity target) Inflicts damage on the given target.abstract voidInitializes the base texture.booleanisAlive()Checks if the entity is alive.booleanisCursed()Checks if the entity is cursed.booleanisDead()Checks if the entity is dead.booleanChecks if the entity is inside the map.voidInflicts knockback on the entity.voidsetAttackValue(int value) Set the attack value of the entity to the given value.voidsetDirection(Direction dir) Set the currentDirectionof the entity to the given value.voidsetHealthValue(int value) Set the current health value of the entity to the given value.voidsetInvincibleCounter(int counter) Set the current invincible counter of the entity to the given value.voidsetKnockbackCounter(int counter) Set the current knockback counter to the given value.voidsetMaxHealthValue(int value) Set the max health value of the entity to the given value.voidsetPreviousDirection(Direction previousDirection) Set the previous direction of the entity to the given value.voidSet theRendererwhere the entity will be drawn on.voidsetSpeed(int speed) Set the speed of the entity to the given value.voidsetX(int x) Set the x coordinate of the entity to the given value.voidsetY(int y) Set the y coordinate of the entity to the given value.voidupdate()Updates the entity.
-
Field Details
-
maxHealingCounter
public static final int maxHealingCounterConstant for the max value of healing counter.- See Also:
-
maxHitTick
public static final int maxHitTickConstant for the max value of hit cooldown.- See Also:
-
maxKnockbackCounter
public static final int maxKnockbackCounterConstant for the max value of knockback counter.- See Also:
-
maxInvincibleCounter
public static final int maxInvincibleCounterConstant for the max value of invincible counter.- See Also:
-
render
TheRendererwhere the entity will be drawn on. -
game
TheGamewhere the entity interacts. -
direction
TheDirectionthe entity moves in. -
previousDirection
The lastDirectionof the entity. -
state
TheEntityStateof the entity. -
x
protected int xThe x coordinate of the entity. -
y
protected int yThe y coordinate of the entity. -
maxHealthValue
protected int maxHealthValueThe max health value of the entity. -
currentHealthValue
protected int currentHealthValueThe current health value of the entity. -
attackValue
protected int attackValueThe attack damage value of the entity. -
speed
protected int speedThe speed of the entity. -
basedSpeed
protected int basedSpeedThe based speed of the entity. -
isCursed
protected boolean isCursedA variable to see if the entity is cursed. -
solidArea
The hitbox of the entity. -
solidAreaDefaultX
protected int solidAreaDefaultXThe default x coordinate of the hitbox. -
solidAreaDefaultY
protected int solidAreaDefaultYThe default y coordinate of the hitbox. -
spriteCounter
protected int spriteCounterThe sprite counter, which is used for the animation -
healingCounter
protected int healingCounterThe default healing counter. -
hitTick
protected int hitTickThe default hit cooldown. -
knockbackCounter
protected int knockbackCounterThe default knockback counter; -
invincibleCounter
protected int invincibleCounterThe default invincible counter.
-
-
Constructor Details
-
Entity
Creates a new Entity. Construction of a new, plain Entity is not allowed. Construction has to be explicitly typed (e.g. Player, Slime,...).
-
-
Method Details
-
isInRange
Checks if the entity is inside the map.- Parameters:
tileMap- the mapx- the x coordinatey- 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
Description copied from interface:IAttackableInflicts damage on the given target.- Specified by:
inflictDamagein interfaceIAttackable- 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
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
Checks if the entity collides with any other entity in the given list.- Parameters:
targetList- the list of all the target entitiescurrentEntityDirection- the currentDirectionof 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 indexmaxIndex- the max index- Returns:
- the new index
-
getRender
Gets theRendererwhere the entity will be drawn on.- Returns:
- the
Rendererwhere the entity will be drawn on
-
setRender
Set theRendererwhere the entity will be drawn on.- Parameters:
render- theRendererwhere the entity will be drawn on
-
getGame
Gets theGamewhere the entity interacts.- Returns:
- the
Gamewhere 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
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
Gets the currentDirectionof the entity.- Returns:
- the current
Directionof the entity
-
setDirection
Set the currentDirectionof the entity to the given value.- Parameters:
dir- the given value
-
getPreviousDirection
Gets the previous direction of the entity.- Returns:
- the previous direction of the entity
-
setPreviousDirection
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:IAttackableSet the attack value of the entity to the given value.- Specified by:
setAttackValuein interfaceIAttackable- Parameters:
value- the given value
-
getAttackValue
public int getAttackValue()Description copied from interface:IAttackableGets the attack value of the entity.- Specified by:
getAttackValuein interfaceIAttackable- Returns:
- the attack value of the entity
-
setHealthValue
public void setHealthValue(int value) Description copied from interface:IAttackableSet the current health value of the entity to the given value.- Specified by:
setHealthValuein interfaceIAttackable- Parameters:
value- the given value
-
getHealthValue
public int getHealthValue()Description copied from interface:IAttackableGets the current health value of the entity.- Specified by:
getHealthValuein interfaceIAttackable- Returns:
- the current health value of the entity
-
setMaxHealthValue
public void setMaxHealthValue(int value) Description copied from interface:IAttackableSet the max health value of the entity to the given value.- Specified by:
setMaxHealthValuein interfaceIAttackable- Parameters:
value- the given value
-
getMaxHealthValue
public int getMaxHealthValue()Description copied from interface:IAttackableGets the max health value of the entity.- Specified by:
getMaxHealthValuein interfaceIAttackable- 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
Draws the health bar of the entity.- Parameters:
g- theGraphicswhich is used to draw
-
draw
Draws the entity.- Parameters:
g- theGraphicswhich is used to draw
-