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 intcolissionRadius-
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 voidaddComponent(Component component)booleancollidesWith(AbstractEntity ent)spherical collision checkvoiddispose()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)CoordinategetCoord()not copy savejava.util.LinkedList<RenderCell>getCoveredBlocks(RenderStorage rs)get the blocks which must be rendered beforeintgetDimensionZ()The height of the object for depth sorting.floatgetHealth()floatgetLightlevelB()How bright is the object?floatgetLightlevelG()How bright is the object?floatgetLightlevelR()How bright is the object?floatgetMass()Get the mass of the object.java.lang.StringgetName()Returns the name of the objectPointgetPoint()Can be internal reference or shared object.PointgetPosition()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 entitieschargetSpriteCategory()Get the category letter for accessing sprites.bytegetSpriteId()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.bytegetSpriteValue()Get the value.booleanhasPosition()Is the object active on the map?voidheal(byte value)Heals the entity. to-do: should be replaced with messages/eventsbooleanisIndestructible()If the object can not be damaged.booleanisInMemoryArea()true if on chunk which is in memorybooleanisMarkedDS(int id)Check if it is marked in this frame.booleanisOnGround()Is the entity laying/standing on the ground?booleanisSavedPersistent()Is the oject saved on the map?voidmarkAsVisitedDS(int id)Marks as visited in the depth sorting algorithm.static voidregisterEngineEntities()Registers engine entities in a map.static voidregisterEntity(java.lang.String name, java.lang.Class<? extends AbstractEntity> entityClass)Register a class of entities.voidremoveComponent(Component component)voidremoveFromMap()Deletes the object from the map.voidrequestChunk()loads the chunk at the positionvoidsetDamageSounds(java.lang.String[] sound)voidsetDimensionZ(int dimensionZ)Set the height of the object.voidsetHealth(float health)clamps to [0..100].voidsetIndestructible(boolean indestructible)If the object can not be damaged.voidsetLightlevel(float lightlevel)Set the brightness of the object.voidsetMass(float mass)voidsetName(java.lang.String name)voidsetPosition(Point pos)keeps the referencevoidsetPosition(Position pos)Set the coordinates without safety check.voidsetSavePersistent(boolean persisent)Mark objects to not be saved in disk.voidsetSpriteCategory(char c)Set the spriteCategory used for the lookup of the sprite.voidsetSpriteId(byte id)voidsetSpriteValue(byte value)voidsetUseRawDelta(boolean useRawDelta)booleanshouldBeDisposed()false if in update list of map.AbstractEntityspawn(Point point)Add this entity to the map-> let it spawnvoidtakeDamage(byte value)Called when gets damage.voidupdate(float dt)Updates the logic of the object.booleanuseRawDelta()-
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:AbstractGameObjectReturn the coordinates of the object in the game world. Not copy safe as it points to the interaly used object.- Specified by:
getPositionin 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:AbstractGameObjectSet the coordinates without safety check. May use different object pointing to the same position.- Specified by:
setPositionin 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:AbstractGameObjectGet the category letter for accessing sprites.- Specified by:
getSpriteCategoryin 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:AbstractGameObjectReturns the name of the object- Specified by:
getNamein 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:AbstractGameObjectThe height of the object for depth sorting.- Specified by:
getDimensionZin 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:AbstractGameObjectHow bright is the object? The lightlevel is a scale applied to the color. 1 is default value.- Specified by:
getLightlevelRin classAbstractGameObject- Returns:
- 1 is default bright. 0 is black.
-
getLightlevelG
public float getLightlevelG()
Description copied from class:AbstractGameObjectHow bright is the object? The lightlevel is a scale applied to the color. 1 is default value.- Specified by:
getLightlevelGin classAbstractGameObject- Returns:
- 1 is default bright. 0 is black.
-
getLightlevelB
public float getLightlevelB()
Description copied from class:AbstractGameObjectHow bright is the object? The lightlevel is a scale applied to the color. 1 is default value.- Specified by:
getLightlevelBin classAbstractGameObject- Returns:
- 1 is default bright. 0 is black.
-
setLightlevel
public void setLightlevel(float lightlevel)
Description copied from class:AbstractGameObjectSet the brightness of the object. The lightlevel is a scaling factor. 1 is default value.- Specified by:
setLightlevelin 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:AbstractGameObjectCan be internal reference or shared object.- Specified by:
getPointin classAbstractGameObject- Returns:
- See Also:
AbstractGameObject.getPosition()
-
getCoord
public Coordinate getCoord()
Description copied from class:AbstractGameObjectnot copy save- Specified by:
getCoordin 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:AbstractGameObjectthe 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:
getSpriteIdin classAbstractGameObject- Returns:
- in range [0;
RenderCell.OBJECTTYPESNUM].
-
getSpriteValue
public byte getSpriteValue()
Description copied from class:AbstractGameObjectGet the value. It is like a sub-id and can identify the status.- Specified by:
getSpriteValuein 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)
-
-