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 int
The attack damage value of the entity.protected int
The based speed of the entity.protected int
The current health value of the entity.protected Direction
TheDirection
the entity moves in.protected Game
TheGame
where the entity interacts.protected int
The default healing counter.protected int
The default hit cooldown.protected int
The default invincible counter.protected boolean
A variable to see if the entity is cursed.protected int
The default knockback counter;static final int
Constant for the max value of healing counter.protected int
The max health value of the entity.static final int
Constant for the max value of hit cooldown.static final int
Constant for the max value of invincible counter.static final int
Constant for the max value of knockback counter.protected Direction
The lastDirection
of the entity.protected Renderer
TheRenderer
where the entity will be drawn on.protected Rectangle
The hitbox of the entity.protected int
The default x coordinate of the hitbox.protected int
The default y coordinate of the hitbox.protected int
The speed of the entity.protected int
The sprite counter, which is used for the animationprotected EntityState
TheEntityState
of the entity.protected int
The x coordinate of the entity.protected int
The y coordinate of the entity. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
collideWithEntity
(ArrayList<Entity> targetList, Direction currentEntityDirection) Checks if the entity collides with any other entity in the given list.boolean
Checks if the entity collides with the player.boolean
collideWithTile
(Tile[][] tileMap) Checks if the entity collides with any solid tile.void
cursed()
Curses the entity.abstract void
Draws the entity.abstract void
Draws the health bar of the entity.int
Gets the attack value of the entity.Gets the currentDirection
of the entity.getGame()
Gets theGame
where the entity interacts.int
Gets the current health value of the entity.int
Gets the current invincible counter of the entity.int
Gets the current knockback counter of the entity.int
Gets the max health value of the entity.Gets the previous direction of the entity.Gets theRenderer
where the entity will be drawn on.Gets the hitbox of the entity.int
Gets the default x coordinate of the hitbox.int
Gets the default y coordinate of the hitbox.int
getSpeed()
Gets the speed of the entity.int
Gets the speed of the entity when swimming.int
getX()
Gets the x coordinate of the entity.int
getY()
Gets the y coordinate of the entity.void
healing()
Heals the entity if the requirements are met.int
increaseImageIndex
(int currentIndex, int maxIndex) Increases the image index so that it will always be in range.void
inflictDamage
(Entity target) Inflicts damage on the given target.abstract void
Initializes the base texture.boolean
isAlive()
Checks if the entity is alive.boolean
isCursed()
Checks if the entity is cursed.boolean
isDead()
Checks if the entity is dead.boolean
Checks if the entity is inside the map.void
Inflicts knockback on the entity.void
setAttackValue
(int value) Set the attack value of the entity to the given value.void
setDirection
(Direction dir) Set the currentDirection
of the entity to the given value.void
setHealthValue
(int value) Set the current health value of the entity to the given value.void
setInvincibleCounter
(int counter) Set the current invincible counter of the entity to the given value.void
setKnockbackCounter
(int counter) Set the current knockback counter to the given value.void
setMaxHealthValue
(int value) Set the max health value of the entity to the given value.void
setPreviousDirection
(Direction previousDirection) Set the previous direction of the entity to the given value.void
Set theRenderer
where the entity will be drawn on.void
setSpeed
(int speed) Set the speed of the entity to the given value.void
setX
(int x) Set the x coordinate of the entity to the given value.void
setY
(int y) Set the y coordinate of the entity to the given value.void
update()
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
TheRenderer
where the entity will be drawn on. -
game
TheGame
where the entity interacts. -
direction
TheDirection
the entity moves in. -
previousDirection
The lastDirection
of the entity. -
state
TheEntityState
of 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:IAttackable
Inflicts damage on the given target.- Specified by:
inflictDamage
in 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 currentDirection
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 indexmaxIndex
- the max index- Returns:
- the new index
-
getRender
Gets theRenderer
where the entity will be drawn on.- Returns:
- the
Renderer
where the entity will be drawn on
-
setRender
Set theRenderer
where the entity will be drawn on.- Parameters:
render
- theRenderer
where the entity will be drawn on
-
getGame
Gets theGame
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
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 currentDirection
of the entity.- Returns:
- the current
Direction
of the entity
-
setDirection
Set the currentDirection
of 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:IAttackable
Set the attack value of the entity to the given value.- Specified by:
setAttackValue
in interfaceIAttackable
- 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 interfaceIAttackable
- 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 interfaceIAttackable
- 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 interfaceIAttackable
- 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 interfaceIAttackable
- 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 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
- theGraphics
which is used to draw
-
draw
Draws the entity.- Parameters:
g
- theGraphics
which is used to draw
-