Class AbstractEntity
- java.lang.Object
-
- com.badlogic.gdx.graphics.g3d.Renderable
-
- com.bombinggames.wurfelengine.core.gameobjects.AbstractGameObject
-
- com.bombinggames.wurfelengine.core.gameobjects.AbstractEntity
-
- All Implemented Interfaces:
com.badlogic.gdx.ai.msg.Telegraph
- Direct Known Subclasses:
Cursor
,EntityBlock
,EntityShadow
,Explosion
,MovableEntity
,ParticleEmitter
,PointLightSource
,SimpleEntity
,Weapon
public abstract class AbstractEntity extends AbstractGameObject implements com.badlogic.gdx.ai.msg.Telegraph
An entity is a game object which has the key feature that is has a position.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description int
colissionRadius
-
Fields inherited from class com.bombinggames.wurfelengine.core.gameobjects.AbstractGameObject
sprite
-
-
Constructor Summary
Constructors Constructor Description AbstractEntity(byte spriteId)
Create an abstractEntity.AbstractEntity(byte spriteId, byte value)
Create an abstractEntity.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addComponent(Component component)
boolean
collidesWith(AbstractEntity ent)
spherical collision checkvoid
dispose()
Deletes the object from the map and every other container.java.util.LinkedList<AbstractEntity>
getCollidingEntities()
* get every entity which is colliding<T> java.util.LinkedList<T>
getCollidingEntities(java.lang.Class<T> filter)
O(n) n:amount of entities. ignores if is obstacle.java.util.LinkedList<Component>
getComponents()
<T extends Component>
ComponentgetComponents(java.lang.Class<T> filterType)
Coordinate
getCoord()
not copy savejava.util.LinkedList<RenderCell>
getCoveredBlocks(RenderStorage rs)
get the blocks which must be rendered beforeint
getDimensionZ()
The height of the object for depth sorting.float
getHealth()
float
getLightlevelB()
How bright is the object?float
getLightlevelG()
How bright is the object?float
getLightlevelR()
How bright is the object?float
getMass()
Get the mass of the object.java.lang.String
getName()
Returns the name of the objectPoint
getPoint()
Can be internal reference or shared object.Point
getPosition()
Return the coordinates of the object in the game world.static java.util.HashMap<java.lang.String,java.lang.Class<? extends AbstractEntity>>
getRegisteredEntities()
Get a map of the registered entitieschar
getSpriteCategory()
Get the category letter for accessing sprites.byte
getSpriteId()
the id of the sprite using for rendering.
By default is the same as the block id but in some cases some objects share one sprite so they can have the same id.byte
getSpriteValue()
Get the value.boolean
hasPosition()
Is the object active on the map?void
heal(byte value)
Heals the entity. to-do: should be replaced with messages/eventsboolean
isIndestructible()
If the object can not be damaged.boolean
isInMemoryArea()
true if on chunk which is in memoryboolean
isMarkedDS(int id)
Check if it is marked in this frame.boolean
isOnGround()
Is the entity laying/standing on the ground?boolean
isSavedPersistent()
Is the oject saved on the map?void
markAsVisitedDS(int id)
Marks as visited in the depth sorting algorithm.static void
registerEngineEntities()
Registers engine entities in a map.static void
registerEntity(java.lang.String name, java.lang.Class<? extends AbstractEntity> entityClass)
Register a class of entities.void
removeComponent(Component component)
void
removeFromMap()
Deletes the object from the map.void
requestChunk()
loads the chunk at the positionvoid
setDamageSounds(java.lang.String[] sound)
void
setDimensionZ(int dimensionZ)
Set the height of the object.void
setHealth(float health)
clamps to [0..100].void
setIndestructible(boolean indestructible)
If the object can not be damaged.void
setLightlevel(float lightlevel)
Set the brightness of the object.void
setMass(float mass)
void
setName(java.lang.String name)
void
setPosition(Point pos)
keeps the referencevoid
setPosition(Position pos)
Set the coordinates without safety check.void
setSavePersistent(boolean persisent)
Mark objects to not be saved in disk.void
setSpriteCategory(char c)
Set the spriteCategory used for the lookup of the sprite.void
setSpriteId(byte id)
void
setSpriteValue(byte value)
void
setUseRawDelta(boolean useRawDelta)
boolean
shouldBeDisposed()
false if in update list of map.AbstractEntity
spawn(Point point)
Add this entity to the map-> let it spawnvoid
takeDamage(byte value)
Called when gets damage.void
update(float dt)
Updates the logic of the object.boolean
useRawDelta()
-
Methods inherited from class com.bombinggames.wurfelengine.core.gameobjects.AbstractGameObject
getColor, getDepth, getPixmap, getRotation, getScaling, getSprite, getSprite, getSpritesheet, getSpritesheetPath, getTextureDiffuse, getTextureNormal, isHidden, loadSheet, render, render, setColor, setCustomSpritesheet, setHidden, setRotation, setScaling, shouldBeRendered, staticDispose, updateSpriteCache
-
-
-
-
Field Detail
-
colissionRadius
public final int colissionRadius
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractEntity
public AbstractEntity(byte spriteId)
Create an abstractEntity.- Parameters:
spriteId
- objects with id = -1 will be deleted. 0 are invisible objects
-
AbstractEntity
public AbstractEntity(byte spriteId, byte value)
Create an abstractEntity.- Parameters:
spriteId
- objects with id -1 are to be deleted. 0 are invisible objectsvalue
-
-
-
Method Detail
-
registerEngineEntities
public static void registerEngineEntities()
Registers engine entities in a map.
-
registerEntity
public static void registerEntity(java.lang.String name, java.lang.Class<? extends AbstractEntity> entityClass)
Register a class of entities. The class must have a constructor without parameters.- Parameters:
name
- the name of the entitie. e.g. "Ball"entityClass
- the class you want to register
-
getRegisteredEntities
public static java.util.HashMap<java.lang.String,java.lang.Class<? extends AbstractEntity>> getRegisteredEntities()
Get a map of the registered entities- Returns:
-
update
public void update(float dt)
Updates the logic of the object.- Parameters:
dt
- time since last update in game time
-
getPosition
public final Point getPosition()
Description copied from class:AbstractGameObject
Return the coordinates of the object in the game world. Not copy safe as it points to the interaly used object.- Specified by:
getPosition
in classAbstractGameObject
- Returns:
- Reference to the position object which points to the location in the game world.
- See Also:
AbstractGameObject.getPoint()
-
setPosition
public void setPosition(Position pos)
Description copied from class:AbstractGameObject
Set the coordinates without safety check. May use different object pointing to the same position.- Specified by:
setPosition
in classAbstractGameObject
- Parameters:
pos
- the coordinates you want to set
-
setPosition
public void setPosition(Point pos)
keeps the reference- Parameters:
pos
-
-
isOnGround
public boolean isOnGround()
Is the entity laying/standing on the ground?- Returns:
- true when on the ground. False if in air or not in memory.
-
spawn
public AbstractEntity spawn(Point point)
Add this entity to the map-> let it spawn- Parameters:
point
- the point in the game world where the object is. If it was previously set this is ignored.- Returns:
- returns itself
-
hasPosition
public boolean hasPosition()
Is the object active on the map? If you spawn the object it has a position afterwards- Returns:
-
getSpriteCategory
public char getSpriteCategory()
Description copied from class:AbstractGameObject
Get the category letter for accessing sprites.- Specified by:
getSpriteCategory
in classAbstractGameObject
- Returns:
-
setSpriteCategory
public void setSpriteCategory(char c)
Set the spriteCategory used for the lookup of the sprite.- Parameters:
c
-
-
getName
public java.lang.String getName()
Description copied from class:AbstractGameObject
Returns the name of the object- Specified by:
getName
in classAbstractGameObject
- Returns:
- the name of the object
-
setName
public void setName(java.lang.String name)
- Parameters:
name
-
-
setDimensionZ
public void setDimensionZ(int dimensionZ)
Set the height of the object.- Parameters:
dimensionZ
- game space
-
getDimensionZ
public int getDimensionZ()
Description copied from class:AbstractGameObject
The height of the object for depth sorting.- Specified by:
getDimensionZ
in classAbstractGameObject
- Returns:
- game space
-
isSavedPersistent
public boolean isSavedPersistent()
Is the oject saved on the map?- Returns:
- true if savedin map file.
-
setSavePersistent
public void setSavePersistent(boolean persisent)
Mark objects to not be saved in disk. Gets passed to the children. Temp objects should not be saved.- Parameters:
persisent
- new value of persisent
-
isInMemoryArea
public boolean isInMemoryArea()
true if on chunk which is in memory- Returns:
- See Also:
Coordinate.isInMemoryAreaXY()
-
getMass
public float getMass()
Get the mass of the object.- Returns:
- in kg
-
setMass
public void setMass(float mass)
- Parameters:
mass
- in kg
-
isIndestructible
public boolean isIndestructible()
If the object can not be damaged. Object can still be disposed and removed from map.- Returns:
-
setIndestructible
public void setIndestructible(boolean indestructible)
If the object can not be damaged. Object can still be disposed and removed from map.- Parameters:
indestructible
-
-
takeDamage
public void takeDamage(byte value)
Called when gets damage. Health is between 0 and 100. Plays a sound. It is recommended to use an event to trigger the damaging so that each object manages it's own damage. If is set to indestructible viasetIndestructible(boolean)
can not be damaged.- Parameters:
value
- between 0 and 100- See Also:
isIndestructible()
-
setDamageSounds
public void setDamageSounds(java.lang.String[] sound)
- Parameters:
sound
-
-
heal
public void heal(byte value)
Heals the entity. to-do: should be replaced with messages/events- Parameters:
value
-
-
getLightlevelR
public float getLightlevelR()
Description copied from class:AbstractGameObject
How bright is the object? The lightlevel is a scale applied to the color. 1 is default value.- Specified by:
getLightlevelR
in classAbstractGameObject
- Returns:
- 1 is default bright. 0 is black.
-
getLightlevelG
public float getLightlevelG()
Description copied from class:AbstractGameObject
How bright is the object? The lightlevel is a scale applied to the color. 1 is default value.- Specified by:
getLightlevelG
in classAbstractGameObject
- Returns:
- 1 is default bright. 0 is black.
-
getLightlevelB
public float getLightlevelB()
Description copied from class:AbstractGameObject
How bright is the object? The lightlevel is a scale applied to the color. 1 is default value.- Specified by:
getLightlevelB
in classAbstractGameObject
- Returns:
- 1 is default bright. 0 is black.
-
setLightlevel
public void setLightlevel(float lightlevel)
Description copied from class:AbstractGameObject
Set the brightness of the object. The lightlevel is a scaling factor. 1 is default value.- Specified by:
setLightlevel
in classAbstractGameObject
- Parameters:
lightlevel
- 1 is default bright. 0 is black.
-
getHealth
public float getHealth()
- Returns:
- from maximum 100
-
setHealth
public void setHealth(float health)
clamps to [0..100]. You may prefer damage andheal(byte)
. Ignores invincibility.- Parameters:
health
-- See Also:
takeDamage(byte)
-
setUseRawDelta
public void setUseRawDelta(boolean useRawDelta)
- Parameters:
useRawDelta
-
-
useRawDelta
public boolean useRawDelta()
- Returns:
-
requestChunk
public void requestChunk()
loads the chunk at the position
-
getCollidingEntities
public java.util.LinkedList<AbstractEntity> getCollidingEntities()
* get every entity which is colliding- Returns:
-
getCollidingEntities
public <T> java.util.LinkedList<T> getCollidingEntities(java.lang.Class<T> filter)
O(n) n:amount of entities. ignores if is obstacle.- Type Parameters:
T
-- Parameters:
filter
- only where the filter is true is returned- Returns:
-
collidesWith
public boolean collidesWith(AbstractEntity ent)
spherical collision check- Parameters:
ent
-- Returns:
-
getCoveredBlocks
public java.util.LinkedList<RenderCell> getCoveredBlocks(RenderStorage rs)
get the blocks which must be rendered before- Parameters:
rs
-- Returns:
-
getPoint
public Point getPoint()
Description copied from class:AbstractGameObject
Can be internal reference or shared object.- Specified by:
getPoint
in classAbstractGameObject
- Returns:
- See Also:
AbstractGameObject.getPosition()
-
getCoord
public Coordinate getCoord()
Description copied from class:AbstractGameObject
not copy save- Specified by:
getCoord
in classAbstractGameObject
- Returns:
- See Also:
AbstractGameObject.getPosition()
-
addComponent
public void addComponent(Component component)
- Parameters:
component
-
-
getComponents
public <T extends Component> Component getComponents(java.lang.Class<T> filterType)
- Type Parameters:
T
-- Parameters:
filterType
-- Returns:
-
getComponents
public java.util.LinkedList<Component> getComponents()
-
removeComponent
public void removeComponent(Component component)
- Parameters:
component
-
-
shouldBeDisposed
public boolean shouldBeDisposed()
false if in update list of map.- Returns:
- true if disposing next tick
- See Also:
dispose()
-
removeFromMap
public void removeFromMap()
Deletes the object from the map. The opposite tospawn(Point)
- See Also:
dispose()
,spawn(Point)
-
dispose
public void dispose()
Deletes the object from the map and every other container. The opposite to spawn() but also sets a flag to remove it completely.- See Also:
shouldBeDisposed()
,removeFromMap()
-
getSpriteId
public byte getSpriteId()
Description copied from class:AbstractGameObject
the id of the sprite using for rendering.
By default is the same as the block id but in some cases some objects share one sprite so they can have the same id.- Specified by:
getSpriteId
in classAbstractGameObject
- Returns:
- in range [0;
RenderCell.OBJECTTYPESNUM
].
-
getSpriteValue
public byte getSpriteValue()
Description copied from class:AbstractGameObject
Get the value. It is like a sub-id and can identify the status.- Specified by:
getSpriteValue
in classAbstractGameObject
- Returns:
- in range [0;
RenderCell.VALUESNUM
]. Is -1 if about to destroyed.
-
setSpriteId
public void setSpriteId(byte id)
- Parameters:
id
-
-
setSpriteValue
public void setSpriteValue(byte value)
- Parameters:
value
-
-
isMarkedDS
public final boolean isMarkedDS(int id)
Check if it is marked in this frame. Used for depth sorting.- Parameters:
id
- camera id- Returns:
- See Also:
TopologicalSort.visit(TopoGraphNode)
-
markAsVisitedDS
public void markAsVisitedDS(int id)
Marks as visited in the depth sorting algorithm.- Parameters:
id
- camera id- See Also:
TopologicalSort.visit(TopoGraphNode)
-
-