Class EntityAttributes

java.lang.Object
fr.r1r0r0.deltaengine.model.elements.entity.EntityAttributes

public final class EntityAttributes
extends java.lang.Object
All attributes of an Entity. Used to get and store all Entity attributes, and define actions when these attributes are updated
  • Field Details

    • name

      private final java.lang.String name
    • coordinates

      private Coordinates<java.lang.Double> coordinates
    • sprite

      private Sprite sprite
    • dimension

      private Dimension dimension
    • hitBox

      private Dimension hitBox
    • direction

      private Direction direction
    • speed

      private double speed
    • attachedAI

      private AI attachedAI
    • collisionsEvents

      private final java.util.Map<Entity,​Event> collisionsEvents
    • coordinatesListeners

      private final java.util.Collection<AttributeListener<Coordinates<java.lang.Double>>> coordinatesListeners
    • spriteListeners

      private final java.util.Collection<AttributeListener<Sprite>> spriteListeners
    • dimensionListeners

      private final java.util.Collection<AttributeListener<Dimension>> dimensionListeners
    • hitBoxListeners

      private final java.util.Collection<AttributeListener<Dimension>> hitBoxListeners
    • directionListeners

      private final java.util.Collection<AttributeListener<Direction>> directionListeners
    • speedListeners

      private final java.util.Collection<AttributeListener<java.lang.Double>> speedListeners
  • Constructor Details

    • EntityAttributes

      EntityAttributes​(java.lang.String name, Coordinates<java.lang.Double> coordinates, Sprite sprite, Dimension dimension, Dimension hitBox, Direction direction, double speed)
      Default constructor. Inits all attributes of an Entity
      Parameters:
      name - name of entity
      coordinates - initial coordinates of entity
      sprite - initial sprite of entity
      dimension - dimension of entity
      hitBox - a hit-box
      direction - initial direction of entity
      speed - initial speed of entity
  • Method Details

    • getName

      public java.lang.String getName()
      Returns name of the entity
      Returns:
      String name of the entity
    • getCoordinates

      public Coordinates<java.lang.Double> getCoordinates()
      Get current position of the entity
      Returns:
      Coordinates of the entity
    • setCoordinates

      public void setCoordinates​(Coordinates<java.lang.Double> coordinates)
      Set new position of the entity and triggers all associated triggers
      Parameters:
      coordinates - Coordinates to set
    • getSprite

      public Sprite getSprite()
      Get current sprite of the entity
      Returns:
      Sprite of the entity
    • setSprite

      public void setSprite​(Sprite sprite)
      Set new sprite for the entity and triggers all associated triggers
      Parameters:
      sprite - Sprite new sprite to apply
    • getDimension

      public Dimension getDimension()
      Get current dimension of the entity
      Returns:
      Dimension of the entity
    • setDimension

      public void setDimension​(Dimension dimension)
      Set new dimension for the entity and triggers all associated triggers
      Parameters:
      dimension - new Dimension of the entity
    • getHitBox

      public Dimension getHitBox()
      Return the attribute hit-box
      Returns:
      the attribute hit-box
    • setHitBox

      public void setHitBox​(Dimension dimension)
      Setter for the attribute hitBox
      Parameters:
      dimension - a dimension
    • getDirection

      public Direction getDirection()
      Get current direction of the entity
      Returns:
      Direction current direction of the entity
    • setDirection

      public void setDirection​(Direction direction)
      Set new direction for the entity and triggers all associated triggers
      Parameters:
      direction - new Direction to apply
    • getSpeed

      public double getSpeed()
      Get current speed of the entity
      Returns:
      double current speed
    • setSpeed

      public void setSpeed​(double speed)
      Set new speed for the entity and triggers all associated triggers
      Parameters:
      speed - double new speed to apply
    • getAttachedAI

      public AI getAttachedAI()
      Get current AI of the entity
      Returns:
      AI of the entity
    • setAttachedAI

      public void setAttachedAI​(Entity entity, AI ai) throws AIAlreadyAttachedException
      AI to attach to the entity. Can be called once. Once AI is attached, it is impossible to remove or change it.
      Parameters:
      entity - Entity concerned
      ai - AI to bind
      Throws:
      AIAlreadyAttachedException - if an AI is already attached to this entity
    • getCollisionsEvents

      public java.util.Map<Entity,​Event> getCollisionsEvents()
      Get map of collisions event, to produce actions when entities collide each others
      Returns:
      Map of all registered collision events
    • addCoordinatesListener

      public void addCoordinatesListener​(AttributeListener<Coordinates<java.lang.Double>> e)
      Set a new listener to the Coordinates attribute. Listener will be executed when Coordinates are updated.
      Parameters:
      e - listener to add
    • addSpriteListener

      public void addSpriteListener​(AttributeListener<Sprite> e)
      Set a new listener to the Sprite attribute. Listener will be executed when Sprite is updated.
      Parameters:
      e - listener to add
    • addDimensionListener

      public void addDimensionListener​(AttributeListener<Dimension> e)
      Set a new listener to the Dimension attribute. Listener will be executed when Dimension is updated.
      Parameters:
      e - listener to add
    • addDirectionListener

      public void addDirectionListener​(AttributeListener<Direction> e)
      Set a new listener to the Direction attribute. Listener will be executed when Direction is updated.
      Parameters:
      e - listener to add
    • addSpeedListener

      public void addSpeedListener​(AttributeListener<java.lang.Double> e)
      Set a new listener to the Speed attribute. Listener will be executed when Speed is updated.
      Parameters:
      e - listener to add