Class Character
java.lang.Object
core.GameObject
core.Character
- All Implemented Interfaces:
Hittable
Abstract base class representing a character in the game.
Characters have health points, power, a hitbox, and a size (diameter).
They can be alive or dead and can be attacked or attack others.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected doubleDiameter of the character's hitbox.private intCurrent health points of the character.protected booleanIndicates whether the character is alive.private intMaximum health points the character can have.private intAttack power of the character.Fields inherited from class core.GameObject
x, y -
Constructor Summary
ConstructorsConstructorDescriptionCharacter(double x, double y, int hp, int power, double diameter) Constructs a new Character. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the diameter of the character's hitbox.javafx.geometry.Rectangle2DReturns the hitbox of the character as a rectangle centered on (x, y).intgetHp()Returns the current health points of the character.intgetMaxHp()Returns the maximum health points of the character.intgetPower()Returns the attack power of the character.booleanisAlive()Checks if the character is alive.booleanisDead()Checks if the character is dead.voidsetAlive(boolean alive) Sets whether the character is alive.voidsetDiameter(double diameter) Sets the diameter of the character's hitbox.voidsetHp(int hp) Sets the health points of the character.voidsetMaxHp(int maxHp) Sets the maximum health points of the character.voidsetPower(int power) Sets the attack power of the character.
-
Field Details
-
hp
private int hpCurrent health points of the character. -
power
private int powerAttack power of the character. -
maxHp
private int maxHpMaximum health points the character can have. -
isAlive
protected boolean isAliveIndicates whether the character is alive. -
diameter
protected double diameterDiameter of the character's hitbox.
-
-
Constructor Details
-
Character
public Character(double x, double y, int hp, int power, double diameter) Constructs a new Character.- Parameters:
x- X position of the character's center.y- Y position of the character's center.hp- Initial health points.power- Attack power of the character.diameter- Diameter of the character's hitbox.
-
-
Method Details
-
isDead
public boolean isDead()Checks if the character is dead.- Returns:
- true if the character is dead, false otherwise.
-
getHitbox
-
getDiameter
public double getDiameter()Returns the diameter of the character's hitbox.- Specified by:
getDiameterin interfaceHittable- Returns:
- Diameter of the character.
-
setDiameter
public void setDiameter(double diameter) Sets the diameter of the character's hitbox. Negative values are clamped to 0.- Parameters:
diameter- Diameter to set.
-
getHp
public int getHp()Returns the current health points of the character.- Returns:
- Current HP.
-
setHp
public void setHp(int hp) Sets the health points of the character. Values are clamped between 0 and maxHp.- Parameters:
hp- Health points to set.
-
setMaxHp
public void setMaxHp(int maxHp) Sets the maximum health points of the character. Values below 0 are clamped to 0.- Parameters:
maxHp- Maximum HP to set.
-
getMaxHp
public int getMaxHp()Returns the maximum health points of the character.- Returns:
- Maximum HP.
-
getPower
public int getPower()Returns the attack power of the character.- Returns:
- Power of the character.
-
setPower
public void setPower(int power) Sets the attack power of the character. Values below 1 are clamped to 1.- Parameters:
power- Power to set.
-
setAlive
public void setAlive(boolean alive) Sets whether the character is alive.- Parameters:
alive- True if alive, false otherwise.
-
isAlive
-