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>blockTargetprivate EntityAttributesentityAttributes -
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 voidclearAllCollisionEvents()Clear all collision events.voidclearCollisionEvent(Entity entity)Clear all collision events bound to given entityAIgetAI()Get attached AI of the entityEntityAttributesgetAttributes()Get all attributes packaged in an object, allowing to getting, setting them or attach listeners when they are updatedCoordinates<java.lang.Integer>getBlockTarget()EventgetCollisionEvent(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.DimensiongetDimension()Return dimension of the Element.DirectiongetDirection()Current direction of the entityDimensiongetHitBox()Getter fot the attribute hitBoxjava.lang.StringgetName()Name getter of the elementdoublegetSpeed()Current speed of the entity.SpritegetSprite()Returns sprite of the elementvoidresetBlockTarget()voidsetAI(AI ai)AI to attach to the entity.voidsetBlockTarget(Coordinates<java.lang.Integer> blockTarget)voidsetCollisionEvent(Entity entity, Event event)Set a new collision event bound to given entity.voidsetCoordinates(Coordinates<java.lang.Double> coordinates)Allows setting new coordinates for the element.voidsetDimension(Dimension dimension)Allows to set dimension of the element, representing its size.voidsetDirection(Direction direction)Set current direction of the entityvoidsetHitBox(Dimension hitBox)Setter for the attribute hitBoxvoidsetSpeed(double speed)Set new current speed of the entity.voidsetSprite(Sprite sprite)Set sprite of an elementbooleantestCollide(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:ElementReturn dimension of the Element. Represents the size of the Element.- Specified by:
getDimensionin interfaceElement<java.lang.Double>- Returns:
- Dimension of the element
-
setDimension
Description copied from interface:ElementAllows to set dimension of the element, representing its size.- Specified by:
setDimensionin interfaceElement<java.lang.Double>- Parameters:
dimension- Dimension to set
-
getSprite
Description copied from interface:ElementReturns sprite of the element -
setSprite
Description copied from interface:ElementSet sprite of an element -
getCoordinates
Description copied from interface:ElementCoordinates of the element in the game.- Specified by:
getCoordinatesin interfaceElement<java.lang.Double>- Returns:
- Coordinates of the element
-
setCoordinates
Description copied from interface:ElementAllows setting new coordinates for the element.- Specified by:
setCoordinatesin interfaceElement<java.lang.Double>- Parameters:
coordinates- new coordinates
-
getName
public java.lang.String getName()Description copied from interface:ElementName 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()
-