java.lang.Object
fr.r1r0r0.deltaengine.model.elements.entity.Entity
All Implemented Interfaces:
Element<java.lang.Double>

public class Entity
extends java.lang.Object
implements Element<java.lang.Double>
An entity of the engine. An entity is detached from cases, and can freely move on them. Every object of the game could be an entity. An AI could also be attached to an Entity.
  • Field Details

  • Constructor Details

    • Entity

      public Entity​(java.lang.String name, Coordinates<java.lang.Double> coords, Sprite sprite, Dimension dimension, Dimension hitBox)
      Default constructor. Defines all attributes to an entity.
      Parameters:
      name - name of the entity
      coords - coordinates of the entity
      sprite - sprite of the entity
      dimension - a dimension
      hitBox - a dimension
    • Entity

      public Entity​(java.lang.String name, Coordinates<java.lang.Double> coords, Sprite sprite, Dimension dimension)
      Constructor
      Parameters:
      name - a name
      coords - a coordinates
      sprite - a sprite
      dimension - a dimension
  • Method Details

    • getHitBox

      public Dimension getHitBox()
      Getter fot the attribute hitBox
      Returns:
      the attribute hitBox
    • setHitBox

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

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

      public void setDirection​(Direction direction)
      Set current direction of the entity
      Parameters:
      direction - current direction
    • getSpeed

      public double getSpeed()
      Current speed of the entity. Speed is in case/frame_rate.
      If current frame_rate is 60, then an entity with 1 of speed will move one case to another in 60 frames.
      Returns:
      double speed entity
    • setSpeed

      public void setSpeed​(double speed)
      Set new current speed of the entity. Speed is in case/frame_rate.
      If current frame_rate is 60, then an entity with 1 of speed will move one case to another in 60 frames.
      Parameters:
      speed - speed to set
    • setAI

      public void setAI​(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:
      ai - AI to attach to the entity
      Throws:
      AIAlreadyAttachedException - if an AI is already attached to the entity
    • getAI

      public AI getAI()
      Get attached AI of the entity
      Returns:
      attached AI
    • getDimension

      public Dimension getDimension()
      Description copied from interface: Element
      Return dimension of the Element. Represents the size of the Element.
      Specified by:
      getDimension in interface Element<java.lang.Double>
      Returns:
      Dimension of the element
    • setDimension

      public void setDimension​(Dimension dimension)
      Description copied from interface: Element
      Allows to set dimension of the element, representing its size.
      Specified by:
      setDimension in interface Element<java.lang.Double>
      Parameters:
      dimension - Dimension to set
    • getSprite

      public Sprite getSprite()
      Description copied from interface: Element
      Returns sprite of the element
      Specified by:
      getSprite in interface Element<java.lang.Double>
      Returns:
      Sprite of the element
    • setSprite

      public void setSprite​(Sprite sprite)
      Description copied from interface: Element
      Set sprite of an element
      Specified by:
      setSprite in interface Element<java.lang.Double>
      Parameters:
      sprite - sprite to set
    • getCoordinates

      public Coordinates<java.lang.Double> getCoordinates()
      Description copied from interface: Element
      Coordinates of the element in the game.
      Specified by:
      getCoordinates in interface Element<java.lang.Double>
      Returns:
      Coordinates of the element
    • setCoordinates

      public void setCoordinates​(Coordinates<java.lang.Double> coordinates)
      Description copied from interface: Element
      Allows setting new coordinates for the element.
      Specified by:
      setCoordinates in interface Element<java.lang.Double>
      Parameters:
      coordinates - new coordinates
    • getName

      public java.lang.String getName()
      Description copied from interface: Element
      Name getter of the element
      Specified by:
      getName in interface Element<java.lang.Double>
      Returns:
      String name of the element
    • setCollisionEvent

      public void setCollisionEvent​(Entity entity, Event event)
      Set a new collision event bound to given entity.
      Parameters:
      entity - entity to react with
      event - event to play when a collision is detected
    • clearCollisionEvent

      public void clearCollisionEvent​(Entity entity)
      Clear all collision events bound to given entity
      Parameters:
      entity - bound entity to clear events
    • clearAllCollisionEvents

      public void clearAllCollisionEvents()
      Clear all collision events.
    • getCollisionEvent

      public Event getCollisionEvent​(Entity entity)
      Return the event matching to the entity given
      Parameters:
      entity - an entity
      Returns:
      the event matching to the entity given, the VoidEvent is return if there is no matching event
    • getCollisionPoints

      private java.util.Collection<Coordinates<java.lang.Double>> getCollisionPoints()
      Return the collision points, a list of coordinates used to calc if there is a collision between 2 entities. The hit-box is a rectangle, with a left-top point corresponding to attribute coords, and width/height are determined by the attribute dimension. Collisions points are calc using class CollisionPoints
      Returns:
      a list of coordinates representing collision points
    • testCollide

      public boolean testCollide​(Entity other)
      Return is there is the current entity is colliding the other entity given. There is a collision if one of the collision points of the current entity is contained in the hit-box of the other entity.
      Parameters:
      other - an entity
      Returns:
      if there is a collision
    • getAttributes

      public EntityAttributes getAttributes()
      Get all attributes packaged in an object, allowing to getting, setting them or attach listeners when they are updated
      Returns:
      EntityAttribute all entity attributes
    • setBlockTarget

      public void setBlockTarget​(Coordinates<java.lang.Integer> blockTarget)
    • getBlockTarget

      public Coordinates<java.lang.Integer> getBlockTarget()
    • resetBlockTarget

      public void resetBlockTarget()