Class Character

All Implemented Interfaces:
Hittable
Direct Known Subclasses:
Enemy, Player

public abstract class Character extends GameObject implements 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

    Fields
    Modifier and Type
    Field
    Description
    protected double
    Diameter of the character's hitbox.
    private int
    Current health points of the character.
    protected boolean
    Indicates whether the character is alive.
    private int
    Maximum health points the character can have.
    private int
    Attack power of the character.

    Fields inherited from class core.GameObject

    x, y
  • Constructor Summary

    Constructors
    Constructor
    Description
    Character(double x, double y, int hp, int power, double diameter)
    Constructs a new Character.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the diameter of the character's hitbox.
    javafx.geometry.Rectangle2D
    Returns the hitbox of the character as a rectangle centered on (x, y).
    int
    Returns the current health points of the character.
    int
    Returns the maximum health points of the character.
    int
    Returns the attack power of the character.
    boolean
    Checks if the character is alive.
    boolean
    Checks if the character is dead.
    void
    setAlive(boolean alive)
    Sets whether the character is alive.
    void
    setDiameter(double diameter)
    Sets the diameter of the character's hitbox.
    void
    setHp(int hp)
    Sets the health points of the character.
    void
    setMaxHp(int maxHp)
    Sets the maximum health points of the character.
    void
    setPower(int power)
    Sets the attack power of the character.

    Methods inherited from class core.GameObject

    getX, getY, render, setX, setY, update

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface core.Hittable

    onDead, onHit
  • Field Details

    • hp

      private int hp
      Current health points of the character.
    • power

      private int power
      Attack power of the character.
    • maxHp

      private int maxHp
      Maximum health points the character can have.
    • isAlive

      protected boolean isAlive
      Indicates whether the character is alive.
    • diameter

      protected double diameter
      Diameter 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

      public javafx.geometry.Rectangle2D getHitbox()
      Returns the hitbox of the character as a rectangle centered on (x, y).
      Specified by:
      getHitbox in interface Hittable
      Returns:
      Rectangle2D representing the character's hitbox.
    • getDiameter

      public double getDiameter()
      Returns the diameter of the character's hitbox.
      Specified by:
      getDiameter in interface Hittable
      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

      public boolean isAlive()
      Checks if the character is alive.
      Specified by:
      isAlive in interface Hittable
      Returns:
      True if alive, false otherwise.