Package com.deco2800.game.entities
Class Entity
java.lang.Object
com.deco2800.game.entities.Entity
public class Entity
extends java.lang.Object
Core entity class. Entities exist in the game and are updated each frame. All entities have a
 position and scale, but have no default behaviour. Components should be added to an entity to
 give it specific behaviour. This class should not be inherited or modified directly.
 
Example use:
Entity player = new Entity() .addComponent(new RenderComponent()) .addComponent(new PlayerControllerComponent()); ServiceLocator.getEntityService().register(player);
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEntity.DisappearType - 
Constructor Summary
 - 
Method Summary
Modifier and Type Method Description EntityaddComponent(Component component)Add a component to the entity.voidcreate()Create the entity and start running.voiddispose()Dispose of the entity.voiddisposeExceptAnimationComponent()Dispose of the entity.voidearlyUpdate()Perform an early update on all components.booleanequals(java.lang.Object obj)floatgetAnimationTime()Get method of animationTime.Vector2getCenterPosition()Get the entity's center position<T extends Component>
TgetComponent(java.lang.Class<T> type)Get a component of type T on the entity.EventHandlergetEvents()Get the event handler attached to this entity.intgetId()This entity's unique ID.Vector2getPosition()Get the entity's game position.Vector2getScale()Get the entity's scale.java.lang.StringgetType()Get entity type.intgetZIndex()Get the entity's zIndex.inthashCode()booleanisDisappear()Get method of disappear.booleanisDispose()Get method of dispose.booleanisRemoveCollision()Getter method of removeCollisionbooleanisRemoveTexture()Get method of removeTexture.voidremoveAfterAnimation()Let the obstacles disappear after playing the animation for animationTime second.voidremoveAfterParticle()Let the obstacles disappear after playing the particle for particleTime second.voidscaleHeight(float y)Set the entity's height and scale the width to maintain aspect ratio.voidscaleWidth(float x)Set the entity's width and scale the height to maintain aspect ratio.voidsetDisappearAfterAnimation(float animationTime, Entity.DisappearType disappearType)Set disappear to true.voidsetDisappearAfterParticle(float particleTime, Entity.DisappearType disappearType)Set disappear to true.voidsetDispose()Set dispose to true.voidsetEnabled(boolean enabled)Enable or disable an entity.voidsetParticleTime(float particleTime)voidsetPosition(float x, float y)Set the entity's game position.voidsetPosition(Vector2 position)Set the entity's game position.voidsetPosition(Vector2 position, boolean notify)Set the entity's game position and optionally notifies listeners.voidsetRemoveCollision()Set removeCollision to true.voidsetRemoveTexture()Set removeTexture to true.voidsetScale(float x, float y)Set the entity's scale.voidsetScale(Vector2 scale)Set the entity's scale.voidsetZIndex(int zIndex)Set the entity's zIndex.java.lang.StringtoString()voidupdate()Perform an update on all components.voidupdateSpeed(Vector2 speed) 
- 
Constructor Details
 - 
Method Details
- 
setEnabled
public void setEnabled(boolean enabled)Enable or disable an entity. Disabled entities do not run update() or earlyUpdate() on their components, but can still be disposed.- Parameters:
 enabled- true for enable, false for disable.
 - 
getType
public java.lang.String getType()Get entity type.- Returns:
 
 - 
updateSpeed
 - 
setDisappearAfterAnimation
Set disappear to true. These variables play a role in removeAfterAnimation() and update().- Parameters:
 animationTime- Set how long the animation will disappear after playing
 - 
setDisappearAfterParticle
Set disappear to true. These variables play a role in removeAfterParticle() and update().- Parameters:
 particleTime- Set how long the animation will disappear after playing
 - 
setParticleTime
public void setParticleTime(float particleTime) - 
setRemoveTexture
public void setRemoveTexture()Set removeTexture to true. The code that works subsequently is in update. - 
setRemoveCollision
public void setRemoveCollision()Set removeCollision to true. The code that works subsequently is in update. When the character's attack hits an obstacle, the obstacle triggers the effect of collision disappearance. However, due to the issue of the animation's playing time, the character will still lose blood if the character collides with an obstacle when the animation is not completed. Therefore, when a character attacks, the obstacle needs to be removed in advance of the collision component. Note: only use when attack to obstacles. - 
setDispose
public void setDispose()Set dispose to true. The code that works subsequently is in update. - 
isDisappear
public boolean isDisappear()Get method of disappear. - 
isRemoveTexture
public boolean isRemoveTexture()Get method of removeTexture. - 
isRemoveCollision
public boolean isRemoveCollision()Getter method of removeCollision- Returns:
 
 - 
isDispose
public boolean isDispose()Get method of dispose. - 
getAnimationTime
public float getAnimationTime()Get method of animationTime.- Returns:
 - How long the animation will disappear after playing
 
 - 
getPosition
Get the entity's game position.- Returns:
 - position
 
 - 
setPosition
Set the entity's game position.- Parameters:
 position- new position.
 - 
setPosition
public void setPosition(float x, float y)Set the entity's game position.- Parameters:
 x- new x positiony- new y position
 - 
setPosition
Set the entity's game position and optionally notifies listeners.- Parameters:
 position- new position.notify- true to notify (default), false otherwise
 - 
getScale
Get the entity's scale. Used for rendering and physics bounding box calculations.- Returns:
 - Scale in x and y directions. 1 = 1 metre.
 
 - 
setScale
Set the entity's scale.- Parameters:
 scale- new scale in metres
 - 
setZIndex
public void setZIndex(int zIndex)Set the entity's zIndex.- Parameters:
 zIndex- Draw priority of the current entity
 - 
getZIndex
public int getZIndex()Get the entity's zIndex. This is not the final drawing priority. Called by "getZIndex()" in RenderComponent.java.- Returns:
 - Current zIndex value
 
 - 
setScale
public void setScale(float x, float y)Set the entity's scale.- Parameters:
 x- width in metresy- height in metres
 - 
scaleWidth
public void scaleWidth(float x)Set the entity's width and scale the height to maintain aspect ratio.- Parameters:
 x- width in metres
 - 
scaleHeight
public void scaleHeight(float y)Set the entity's height and scale the width to maintain aspect ratio.- Parameters:
 y- height in metres
 - 
getCenterPosition
Get the entity's center position- Returns:
 - center position
 
 - 
getComponent
Get a component of type T on the entity.- Type Parameters:
 T- The component type, e.g. RenderComponent- Parameters:
 type- The component class, e.g. RenderComponent.class- Returns:
 - The entity component, or null if nonexistent.
 
 - 
addComponent
Add a component to the entity. Can only be called before the entity is registered in the world.- Parameters:
 component- The component to add. Only one component of a type can be added to an entity.- Returns:
 - Itself
 
 - 
dispose
public void dispose()Dispose of the entity. This will dispose of all components on this entity. - 
disposeExceptAnimationComponent
public void disposeExceptAnimationComponent()Dispose of the entity. This will dispose of all components on this entity. - 
removeAfterAnimation
public void removeAfterAnimation()Let the obstacles disappear after playing the animation for animationTime second. Is called by update().The purpose of setting this method: When dispose() is used for animation components, all entities that use the same animation become black boxes. Therefore, this method is currently used to make obstacles disappear.
 - 
removeAfterParticle
public void removeAfterParticle()Let the obstacles disappear after playing the particle for particleTime second. Is called by update(). - 
create
public void create()Create the entity and start running. This is called when the entity is registered in the world, and should not be called manually. - 
earlyUpdate
public void earlyUpdate()Perform an early update on all components. This is called by the entity service and should not be called manually. - 
update
public void update()Perform an update on all components. This is called by the entity service and should not be called manually. - 
getId
public int getId()This entity's unique ID. Used for equality checks- Returns:
 - unique ID
 
 - 
getEvents
Get the event handler attached to this entity. Can be used to trigger events from an attached component, or listen to events from a component.- Returns:
 - entity's event handler
 
 - 
equals
public boolean equals(java.lang.Object obj)- Overrides:
 equalsin classjava.lang.Object
 - 
hashCode
public int hashCode()- Overrides:
 hashCodein classjava.lang.Object
 - 
toString
public java.lang.String toString()- Overrides:
 toStringin classjava.lang.Object
 
 -