Class Creature

All Implemented Interfaces:
EntityRenderedListener, EntityRenderListener, ICollisionEntity, ICombatEntity, IEntity, IMobileEntity, Tweenable, EventListener
Direct Known Subclasses:
ScriptedProjectile

public class Creature extends CombatEntity implements IMobileEntity
The Creature class extends the CombatEntity class and implements the IMobileEntity interface. It represents a creature entity in the game with movement and combat capabilities.
  • Constructor Details

  • Method Details

    • onMoved

      public void onMoved(IMobileEntity.EntityMovedListener listener)
      Description copied from interface: IMobileEntity

      Adds the specified entity moved listener to receive events when this entity was moved.

      In comparison to the EntityTransformListener.locationChanged(IEntity) event, this provides some additional information about the movement (e.g. distance) and is only fired if the entity instance is currently loaded.

      Specified by:
      onMoved in interface IMobileEntity
      Parameters:
      listener - The listener to add.
    • removeMovedListener

      public void removeMovedListener(IMobileEntity.EntityMovedListener listener)
      Description copied from interface: IMobileEntity
      Removes the specified entity moved listener.
      Specified by:
      removeMovedListener in interface IMobileEntity
      Parameters:
      listener - The listener to remove.
    • getTweenValues

      public float[] getTweenValues(TweenType tweenType)
      Description copied from interface: Tweenable
      Gets one or many values from the target object associated to the given tween type. It is used by the Tween Engine to determine starting values.
      Specified by:
      getTweenValues in interface Tweenable
      Overrides:
      getTweenValues in class CombatEntity
      Parameters:
      tweenType - The tween type of this interpolation, determining which values are modified.
      Returns:
      The array of current tween values.
    • setTweenValues

      public void setTweenValues(TweenType tweenType, float[] newValues)
      Description copied from interface: Tweenable
      This method is called in a Tween's update() method to set the new interpolated values.
      Specified by:
      setTweenValues in interface Tweenable
      Overrides:
      setTweenValues in class CombatEntity
      Parameters:
      tweenType - The tween type of this interpolation, determining which values are modified.
      newValues - The new values determined by the tween equation.
    • getAcceleration

      public int getAcceleration()
      Description copied from interface: IMobileEntity
      Gets a value that defines how long it takes the entity to reach the full velocity (in ms).
      Specified by:
      getAcceleration in interface IMobileEntity
      Returns:
      the acceleration value
    • getDeceleration

      public int getDeceleration()
      Description copied from interface: IMobileEntity
      Gets a value that defines how long it takes the entity to stop when slowing down from movements (in ms).
      Specified by:
      getDeceleration in interface IMobileEntity
      Returns:
      the deceleration value
    • getFacingDirection

      public Direction getFacingDirection()
      Gets the facing direction of the creature based on its current angle.
      Returns:
      The direction the creature is facing.
    • movement

      public IMovementController movement()
      Description copied from interface: IMobileEntity
      Gets the movement controller.
      Specified by:
      movement in interface IMobileEntity
      Returns:
      the movement controller
    • getSpritesheetName

      public String getSpritesheetName()

      Gets the current spritesheet name of this instance. Overwriting this allows for a more sophisticated logic that determines the sprite to be used; e.g. This method could append certain properties of the creature (state, weapon, ...) to the default string.

      The value of this method will be used e.g. by the CreatureAnimationController to determine the animation that it should play.

      Returns:
      The current spritesheet name of this instance.
    • getTickVelocity

      public float getTickVelocity()
      Description copied from interface: IMobileEntity
      Gets the entity's velocity in PIXELS per tick.
      Specified by:
      getTickVelocity in interface IMobileEntity
      Returns:
      The velocity in pixel per tick.
    • getVelocity

      public Attribute<Float> getVelocity()
      Description copied from interface: IMobileEntity
      Gets the entity's velocity in PIXELS per Second.
      Specified by:
      getVelocity in interface IMobileEntity
      Returns:
      the velocity in pixel per second.
    • isScaling

      public boolean isScaling()
      Checks if the creature's sprite is being scaled with the entity dimensions.
      Returns:
      true if the sprite is being scaled, false otherwise.
    • isIdle

      public boolean isIdle()
      Checks if the creature is idle.
      Returns:
      true if the creature has not moved for a duration longer than the idle delay, false otherwise.
    • setAcceleration

      public void setAcceleration(int acceleration)
      Description copied from interface: IMobileEntity
      Sets the acceleration for this entity. Acceleration is a value that defines how long it takes the entity to reach the full velocity when starting to move (in ms). *
      Specified by:
      setAcceleration in interface IMobileEntity
      Parameters:
      acceleration - the new acceleration
    • setDeceleration

      public void setDeceleration(int deceleration)
      Description copied from interface: IMobileEntity
      Sets the deceleration for this entity. deceleration is a value that defines how long it takes the entity to stop when slowing down from movements (in ms).
      Specified by:
      setDeceleration in interface IMobileEntity
      Parameters:
      deceleration - the new deceleration
    • setFacingDirection

      public void setFacingDirection(Direction facingDirection)
      Sets the facing direction of the creature.
      Parameters:
      facingDirection - The direction to set the creature's facing angle to.
    • setLocation

      public void setLocation(Point2D location)
      Description copied from class: Entity
      Sets the map location.
      Specified by:
      setLocation in interface IEntity
      Overrides:
      setLocation in class CollisionEntity
      Parameters:
      location - the new map location
    • setTurnOnMove

      public void setTurnOnMove(boolean turn)
      Description copied from interface: IMobileEntity
      Sets the turn on move parameter for this entity. It specifies if the entity will change its angle to the direction of the move destination when moved.
      Specified by:
      setTurnOnMove in interface IMobileEntity
      Parameters:
      turn - the new turn on move parameter.
    • setSpritesheetName

      public void setSpritesheetName(String spritesheetName)
      Sets the spritesheet name for this creature.
      Parameters:
      spritesheetName - The name of the spritesheet to set.
    • setScaling

      public void setScaling(boolean scaling)
      Sets whether the creature's sprite should be scaled with the entity dimensions.
      Parameters:
      scaling - true to scale the sprite, false otherwise.
    • setVelocity

      public void setVelocity(float velocity)
      Description copied from interface: IMobileEntity
      Sets the base value on the velocity attribute of this instance.
      Specified by:
      setVelocity in interface IMobileEntity
      Parameters:
      velocity - The velocity to be set.
      See Also:
    • turnOnMove

      public boolean turnOnMove()
      Description copied from interface: IMobileEntity
      Gets the turn on move parameter for this entity. It specifies if the entity will change its angle to the direction of the move destination when moved.
      Specified by:
      turnOnMove in interface IMobileEntity
      Returns:
      true, if the entity will change its angle to the direction of the move destination when being moved
    • toString

      public String toString()
      Overrides:
      toString in class Entity
    • updateAnimationController

      protected void updateAnimationController()
      Updates the animation controller for the creature. This method creates a new animation controller and adds it to the creature's controllers. If the game world environment is loaded, the new controller is attached to the game loop.
    • createAnimationController

      protected IEntityAnimationController<? extends Creature> createAnimationController()
      Creates a new animation controller for the creature.
      Returns:
      A new instance of IEntityAnimationController for the creature.
    • createMovementController

      protected IMovementController createMovementController()
      Creates a new movement controller for the creature.
      Returns:
      A new instance of IMovementController for the creature.
    • getAbilities

      public Collection<Ability> getAbilities()
      Gets all abilities currently registered on this creature.
      Returns:
      A collection of registered abilities.
    • getAbility

      public Optional<Ability> getAbility(String name)
      Gets an ability registered on this creature by its name.
      Parameters:
      name - The name of the ability to retrieve.
      Returns:
      An Optional containing the ability if found, or empty otherwise.
    • getAbility

      public <T extends Ability> Optional<T> getAbility(Class<T> abilityClass)
      Gets the first ability of the specified class registered on this creature.
      Type Parameters:
      T - The ability type.
      Parameters:
      abilityClass - The class of the ability.
      Returns:
      An Optional containing the ability if found, or empty otherwise.
    • hasAbility

      public boolean hasAbility(String name)
      Checks whether this creature has an ability with the specified name.
      Parameters:
      name - The ability name.
      Returns:
      true if the ability exists, false otherwise.
    • hasAbility

      public boolean hasAbility(Class<? extends Ability> abilityClass)
      Checks whether this creature has an ability of the specified class.
      Parameters:
      abilityClass - The class of the ability.
      Returns:
      true if an ability of the class is registered, false otherwise.
    • addAbility

      public void addAbility(Ability ability)
      Adds an ability to this creature.
      Parameters:
      ability - The ability to register.
    • removeAbility

      public void removeAbility(Ability ability)
      Removes an ability from this creature.
      Parameters:
      ability - The ability to remove.
    • removeAbility

      public void removeAbility(String name)
      Removes an ability with the specified name from this creature.
      Parameters:
      name - The name of the ability to remove.
    • cast

      public AbilityExecution cast(String name)
      Casts a registered ability by name.
      Parameters:
      name - The name of the ability to cast.
      Returns:
      The AbilityExecution if cast successfully, or null otherwise.
    • cast

      public <T extends Ability> AbilityExecution cast(Class<T> abilityClass)
      Casts a registered ability of the specified class.
      Type Parameters:
      T - The ability type.
      Parameters:
      abilityClass - The class of the ability to cast.
      Returns:
      The AbilityExecution if cast successfully, or null otherwise.
    • canCast

      public boolean canCast(String name)
      Checks whether a registered ability with the specified name can currently be cast.
      Parameters:
      name - The name of the ability.
      Returns:
      true if the ability exists and can be cast, false otherwise.
    • canCast

      public boolean canCast(Class<? extends Ability> abilityClass)
      Checks whether a registered ability of the specified class can currently be cast.
      Parameters:
      abilityClass - The class of the ability.
      Returns:
      true if the ability exists and can be cast, false otherwise.
    • isOnCooldown

      public boolean isOnCooldown(String name)
      Checks whether a registered ability with the specified name is currently on cooldown.
      Parameters:
      name - The name of the ability.
      Returns:
      true if the ability exists and is on cooldown, false otherwise.
    • isOnCooldown

      public boolean isOnCooldown(Class<? extends Ability> abilityClass)
      Checks whether a registered ability of the specified class is currently on cooldown.
      Parameters:
      abilityClass - The class of the ability.
      Returns:
      true if the ability exists and is on cooldown, false otherwise.
    • createAbility

      public AbilityBuilder createAbility(String name)
      Begins fluently building a new DynamicAbility for this creature.
      Parameters:
      name - The name of the ability.
      Returns:
      An AbilityBuilder configured for this creature.