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 Summary
Fields Modifier and Type Field Description private AIattachedAIprivate java.util.Map<Entity,Event>collisionsEventsprivate Coordinates<java.lang.Double>coordinatesprivate java.util.Collection<AttributeListener<Coordinates<java.lang.Double>>>coordinatesListenersprivate Dimensiondimensionprivate java.util.Collection<AttributeListener<Dimension>>dimensionListenersprivate Directiondirectionprivate java.util.Collection<AttributeListener<Direction>>directionListenersprivate DimensionhitBoxprivate java.util.Collection<AttributeListener<Dimension>>hitBoxListenersprivate java.lang.Stringnameprivate doublespeedprivate java.util.Collection<AttributeListener<java.lang.Double>>speedListenersprivate Spritespriteprivate java.util.Collection<AttributeListener<Sprite>>spriteListeners -
Constructor Summary
Constructors Constructor Description EntityAttributes(java.lang.String name, Coordinates<java.lang.Double> coordinates, Sprite sprite, Dimension dimension, Dimension hitBox, Direction direction, double speed)Default constructor. -
Method Summary
Modifier and Type Method Description voidaddCoordinatesListener(AttributeListener<Coordinates<java.lang.Double>> e)Set a new listener to the Coordinates attribute.voidaddDimensionListener(AttributeListener<Dimension> e)Set a new listener to the Dimension attribute.voidaddDirectionListener(AttributeListener<Direction> e)Set a new listener to the Direction attribute.voidaddSpeedListener(AttributeListener<java.lang.Double> e)Set a new listener to the Speed attribute.voidaddSpriteListener(AttributeListener<Sprite> e)Set a new listener to the Sprite attribute.AIgetAttachedAI()Get current AI of the entityjava.util.Map<Entity,Event>getCollisionsEvents()Get map of collisions event, to produce actions when entities collide each othersCoordinates<java.lang.Double>getCoordinates()Get current position of the entityDimensiongetDimension()Get current dimension of the entityDirectiongetDirection()Get current direction of the entityDimensiongetHitBox()Return the attribute hit-boxjava.lang.StringgetName()Returns name of the entitydoublegetSpeed()Get current speed of the entitySpritegetSprite()Get current sprite of the entityvoidsetAttachedAI(Entity entity, AI ai)AI to attach to the entity.voidsetCoordinates(Coordinates<java.lang.Double> coordinates)Set new position of the entity and triggers all associated triggersvoidsetDimension(Dimension dimension)Set new dimension for the entity and triggers all associated triggersvoidsetDirection(Direction direction)Set new direction for the entity and triggers all associated triggersvoidsetHitBox(Dimension dimension)Setter for the attribute hitBoxvoidsetSpeed(double speed)Set new speed for the entity and triggers all associated triggersvoidsetSprite(Sprite sprite)Set new sprite for the entity and triggers all associated triggersMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
name
private final java.lang.String name -
coordinates
-
sprite
-
dimension
-
hitBox
-
direction
-
speed
private double speed -
attachedAI
-
collisionsEvents
-
coordinatesListeners
private final java.util.Collection<AttributeListener<Coordinates<java.lang.Double>>> coordinatesListeners -
spriteListeners
-
dimensionListeners
-
hitBoxListeners
-
directionListeners
-
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 entitycoordinates- initial coordinates of entitysprite- initial sprite of entitydimension- dimension of entityhitBox- a hit-boxdirection- initial direction of entityspeed- initial speed of entity
-
-
Method Details
-
getName
public java.lang.String getName()Returns name of the entity- Returns:
- String name of the entity
-
getCoordinates
Get current position of the entity- Returns:
- Coordinates of the entity
-
setCoordinates
Set new position of the entity and triggers all associated triggers- Parameters:
coordinates- Coordinates to set
-
getSprite
Get current sprite of the entity- Returns:
- Sprite of the entity
-
setSprite
Set new sprite for the entity and triggers all associated triggers- Parameters:
sprite- Sprite new sprite to apply
-
getDimension
Get current dimension of the entity- Returns:
- Dimension of the entity
-
setDimension
Set new dimension for the entity and triggers all associated triggers- Parameters:
dimension- new Dimension of the entity
-
getHitBox
Return the attribute hit-box- Returns:
- the attribute hit-box
-
setHitBox
Setter for the attribute hitBox- Parameters:
dimension- a dimension
-
getDirection
Get current direction of the entity- Returns:
- Direction current direction of the entity
-
setDirection
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
Get current AI of the entity- Returns:
- AI of the entity
-
setAttachedAI
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 concernedai- AI to bind- Throws:
AIAlreadyAttachedException- if an AI is already attached to this entity
-
getCollisionsEvents
Get map of collisions event, to produce actions when entities collide each others- Returns:
- Map of all registered collision events
-
addCoordinatesListener
Set a new listener to the Coordinates attribute. Listener will be executed when Coordinates are updated.- Parameters:
e- listener to add
-
addSpriteListener
Set a new listener to the Sprite attribute. Listener will be executed when Sprite is updated.- Parameters:
e- listener to add
-
addDimensionListener
Set a new listener to the Dimension attribute. Listener will be executed when Dimension is updated.- Parameters:
e- listener to add
-
addDirectionListener
Set a new listener to the Direction attribute. Listener will be executed when Direction is updated.- Parameters:
e- listener to add
-
addSpeedListener
Set a new listener to the Speed attribute. Listener will be executed when Speed is updated.- Parameters:
e- listener to add
-