Class Entity
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 Summary
Fields Modifier and Type Field Description private Coordinates<java.lang.Integer>
blockTarget
private EntityAttributes
entityAttributes
-
Constructor Summary
Constructors Constructor Description Entity(java.lang.String name, Coordinates<java.lang.Double> coords, Sprite sprite, Dimension dimension)
ConstructorEntity(java.lang.String name, Coordinates<java.lang.Double> coords, Sprite sprite, Dimension dimension, Dimension hitBox)
Default constructor. -
Method Summary
Modifier and Type Method Description void
clearAllCollisionEvents()
Clear all collision events.void
clearCollisionEvent(Entity entity)
Clear all collision events bound to given entityAI
getAI()
Get attached AI of the entityEntityAttributes
getAttributes()
Get all attributes packaged in an object, allowing to getting, setting them or attach listeners when they are updatedCoordinates<java.lang.Integer>
getBlockTarget()
Event
getCollisionEvent(Entity entity)
Return the event matching to the entity givenprivate 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.Coordinates<java.lang.Double>
getCoordinates()
Coordinates of the element in the game.Dimension
getDimension()
Return dimension of the Element.Direction
getDirection()
Current direction of the entityDimension
getHitBox()
Getter fot the attribute hitBoxjava.lang.String
getName()
Name getter of the elementdouble
getSpeed()
Current speed of the entity.Sprite
getSprite()
Returns sprite of the elementvoid
resetBlockTarget()
void
setAI(AI ai)
AI to attach to the entity.void
setBlockTarget(Coordinates<java.lang.Integer> blockTarget)
void
setCollisionEvent(Entity entity, Event event)
Set a new collision event bound to given entity.void
setCoordinates(Coordinates<java.lang.Double> coordinates)
Allows setting new coordinates for the element.void
setDimension(Dimension dimension)
Allows to set dimension of the element, representing its size.void
setDirection(Direction direction)
Set current direction of the entityvoid
setHitBox(Dimension hitBox)
Setter for the attribute hitBoxvoid
setSpeed(double speed)
Set new current speed of the entity.void
setSprite(Sprite sprite)
Set sprite of an elementboolean
testCollide(Entity other)
Return is there is the current entity is colliding the other entity given.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
entityAttributes
-
blockTarget
-
-
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 entitycoords
- coordinates of the entitysprite
- sprite of the entitydimension
- a dimensionhitBox
- a dimension
-
Entity
public Entity(java.lang.String name, Coordinates<java.lang.Double> coords, Sprite sprite, Dimension dimension)Constructor- Parameters:
name
- a namecoords
- a coordinatessprite
- a spritedimension
- a dimension
-
-
Method Details
-
getHitBox
Getter fot the attribute hitBox- Returns:
- the attribute hitBox
-
setHitBox
Setter for the attribute hitBox- Parameters:
hitBox
- a dimension for the hitBox
-
getDirection
Current direction of the entity- Returns:
- direction of the entity
-
setDirection
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
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
Get attached AI of the entity- Returns:
- attached AI
-
getDimension
Description copied from interface:Element
Return dimension of the Element. Represents the size of the Element.- Specified by:
getDimension
in interfaceElement<java.lang.Double>
- Returns:
- Dimension of the element
-
setDimension
Description copied from interface:Element
Allows to set dimension of the element, representing its size.- Specified by:
setDimension
in interfaceElement<java.lang.Double>
- Parameters:
dimension
- Dimension to set
-
getSprite
Description copied from interface:Element
Returns sprite of the element -
setSprite
Description copied from interface:Element
Set sprite of an element -
getCoordinates
Description copied from interface:Element
Coordinates of the element in the game.- Specified by:
getCoordinates
in interfaceElement<java.lang.Double>
- Returns:
- Coordinates of the element
-
setCoordinates
Description copied from interface:Element
Allows setting new coordinates for the element.- Specified by:
setCoordinates
in interfaceElement<java.lang.Double>
- Parameters:
coordinates
- new coordinates
-
getName
public java.lang.String getName()Description copied from interface:Element
Name getter of the element -
setCollisionEvent
Set a new collision event bound to given entity.- Parameters:
entity
- entity to react withevent
- event to play when a collision is detected
-
clearCollisionEvent
Clear all collision events bound to given entity- Parameters:
entity
- bound entity to clear events
-
clearAllCollisionEvents
public void clearAllCollisionEvents()Clear all collision events. -
getCollisionEvent
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
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
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
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
-
getBlockTarget
-
resetBlockTarget
public void resetBlockTarget()
-