Class Environment
- All Implemented Interfaces:
IRenderable
public final class Environment
extends java.lang.Object
implements IRenderable
Constructor Summary
Constructors Constructor Description Environment(IMap map)
Instantiates a newEnvironment
for the specified map.Environment(java.lang.String mapPath)
Instantiates a newEnvironment
for the specified map.Method Summary
Modifier and Type Method Description void
add(IEntity entity)
Adds the specified entity to the environment container.void
add(IRenderable renderable, RenderType renderType)
Adds the specified instance to be rendered with the definedRenderType
whenever the environment's render pipeline is executed.void
addAll(IEntity... entities)
Adds all the specified entities to the environment container.<T extends IEntity>
voidaddAll(java.lang.Iterable<T> entities)
Adds all the specified entities to the environment container.void
addEntityListener(EnvironmentEntityListener listener)
Adds the specified environment entity listener to receive events about entities on this environment.void
addListener(EnvironmentListener listener)
Adds the specified environment listener to receive events about the basic environment life-cycle.java.util.Collection<IEntity>
build(Blueprint blueprint, double x, double y)
Adds entities by the specified blueprint to this environment at the defined location.java.util.Collection<IEntity>
build(Blueprint blueprint, java.awt.geom.Point2D location)
Adds entities by the specified blueprint to this environment at the defined location.void
clear()
Clears all loaded entities and renderable instances from this environment.boolean
contains(int mapId)
Determines whether the environment contains any entity with the specified map ID.boolean
contains(IEntity entity)
Determines whether the environment contains the specified entity.java.util.Collection<ICombatEntity>
findCombatEntities(java.awt.Shape shape)
Attempts to find all combat entities whose hitBox intersects with the specified shape.java.util.Collection<ICombatEntity>
findCombatEntities(java.awt.Shape shape, java.util.function.Predicate<ICombatEntity> condition)
Attempts to find all combat entities whose hitBox intersects with the specified shape.java.util.Collection<IEntity>
findEntities(java.awt.Shape shape)
Attempts to find all entities whose bounding box intersects with the specified shape.IEntity
get(int mapId)
Gets the entity with the specified map ID from this environment.java.util.List<IEntity>
get(int... mapIds)
Gets all entities with the specified map IDs from this environment.<T extends IEntity>
Tget(java.lang.Class<T> clss, int mapId)
Gets the strongly typed entity with the specified map ID from this environment.<T extends IEntity>
Tget(java.lang.Class<T> clss, java.lang.String name)
Gets the strongly typed entity with the specified name from this environment.IEntity
get(java.lang.String name)
Gets the entity with the specified name from this environment.java.util.Collection<java.lang.Integer>
getAllMapIDs()
Gets an immutable collection with all assigned map IDs on this environment.AmbientLight
getAmbientLight()
Gets the ambient light instance of this environment.MapArea
getArea(int mapId)
Gets theMapArea
with the specified map ID from this environment.MapArea
getArea(java.lang.String name)
Gets theMapArea
with the specified name from this environment.java.util.Collection<MapArea>
getAreas()
Gets an immutable collection containing allMapArea
entities on this environment.java.util.Collection<MapArea>
getAreas(java.lang.String tag)
Gets an immutable collection containing allMapArea
entities with the specified tag.<T extends IEntity>
java.util.Collection<T>getByTag(java.lang.Class<? extends T> clss, java.lang.String... tags)
Gets a distinct and strongly named collection of all entities with any of the specified tags.java.util.Collection<IEntity>
getByTag(java.lang.String... tags)
Gets a distinct collection of all entities with any of the specified tags.java.awt.geom.Point2D
getCenter()
Gets the center location of the boundaries defined by the map of this environment.CollisionBox
getCollisionBox(int mapId)
Gets theCollisionBox
with the specified map ID from this environment.CollisionBox
getCollisionBox(java.lang.String name)
Gets theCollisionBox
with the specified name from this environment.java.util.Collection<CollisionBox>
getCollisionBoxes()
Gets an immutable collection containing allCollisionBox
entities on this environment.java.util.Collection<CollisionBox>
getCollisionBoxes(java.lang.String tag)
Gets an immutable collection containing allCollisionBox
entities with the specified tag.java.util.Collection<ICombatEntity>
getCombatEntities()
Gets an immutable collection containing allICombatEntity
entities on this environment.java.util.Collection<ICombatEntity>
getCombatEntities(java.lang.String tag)
Gets an immutable collection containing allICombatEntity
entities with the specified tag.ICombatEntity
getCombatEntity(int mapId)
Gets theICombatEntity
with the specified map ID from this environment.ICombatEntity
getCombatEntity(java.lang.String name)
Gets theICombatEntity
with the specified name from this environment.Creature
getCreature(int mapId)
Gets theCreature
with the specified map ID from this environment.Creature
getCreature(java.lang.String name)
Gets theCreature
with the specified name from this environment.java.util.Collection<Creature>
getCreatures()
Gets an immutable collection containing allCreature
entities on this environment.java.util.Collection<Creature>
getCreatures(java.lang.String tag)
Gets an immutable collection containing allCreature
entities with the specified tag.Emitter
getEmitter(int mapId)
Gets theEmitter
with the specified map ID from this environment.Emitter
getEmitter(java.lang.String name)
Gets theEmitter
with the specified name from this environment.java.util.Collection<Emitter>
getEmitters()
Gets an immutable collection containing allEmitter
entities on this environment.java.util.Collection<Emitter>
getEmitters(java.lang.String tag)
Gets an immutable collection containing allEmitter
entities with the specified tag.java.util.Collection<IEntity>
getEntities()
Gets an immutable collection containing all entities on this environment.java.util.Collection<IEntity>
getEntities(IMapObjectLayer layer)
Gets the entities that are bound to the specified layer.java.util.Collection<IEntity>
getEntities(RenderType renderType)
Gets the entities with the specified render type that are not bound to layers.<T> java.util.Collection<T>
getEntities(java.lang.Class<? extends T> cls)
Gets all entities of the specified type on this environment.<T> java.util.Collection<T>
getEntities(java.lang.Class<? extends T> cls, java.lang.String tag)
Gets all entities of the specified type on this environment.<T> java.util.Collection<T>
getEntities(java.lang.Class<? extends T> cls, java.util.function.Predicate<T> pred)
Gets all entities of the specified type on this environment.java.util.Collection<IEntity>
getEntitiesByLayer(int layerId)
Gets the entities that are bound to layer with the specified layer ID.java.util.Collection<IEntity>
getEntitiesByLayer(java.lang.String name)
Gets the entities that are bound to layer with the specified name.java.util.Map<java.lang.String,java.util.Collection<IEntity>>
getEntitiesByTag()
DON'T USE THIS! THIS IS FOR ENGINE INTERNAL PURPOSES ONLY!.int
getGravity()
Gets the gravity defined for this environment.LightSource
getLightSource(int mapId)
Gets theLightSource
with the specified map ID from this environment.LightSource
getLightSource(java.lang.String name)
Gets theLightSource
with the specified name from this environment.java.util.Collection<LightSource>
getLightSources()
Gets an immutable collection containing allLightSource
entities on this environment.java.util.Collection<LightSource>
getLightSources(java.lang.String tag)
Gets an immutable collection containing allLightSource
entities with the specified tag.static int
getLocalMapId()
Gets the next unique local map id.IMap
getMap()
Gets the map on which this environment is based upon.java.util.Collection<IMobileEntity>
getMobileEntities()
Gets an immutable collection containing allIMobileEntity
instances on this environment.java.util.Collection<IMobileEntity>
getMobileEntities(java.lang.String tag)
Gets an immutable collection containing allIMobileEntity
entities with the specified tag.IMobileEntity
getMobileEntity(int mapId)
Gets theIMobileEntity
with the specified map ID from this environment.IMobileEntity
getMobileEntity(java.lang.String name)
Gets theIMobileEntity
with the specified name from this environment.int
getNextMapId()
Gets the next unique global map id.Prop
getProp(int mapId)
Gets theProp
with the specified map ID from this environment.Prop
getProp(java.lang.String name)
Gets theProp
with the specified name from this environment.java.util.Collection<Prop>
getProps()
Gets an immutable collection containing allProp
entities on this environment.java.util.Collection<Prop>
getProps(java.lang.String tag)
Gets an immutable collection containing allProp
entities with the specified tag.java.util.Collection<IRenderable>
getRenderables(RenderType renderType)
Gets an immutable collection containing allIRenderable
instances for the specified render type on this environment.SoundSource
getSoundSource(int mapId)
Gets theSoundSource
with the specified map ID from this environment.SoundSource
getSoundSource(java.lang.String name)
Gets theSoundSource
with the specified name from this environment.java.util.Collection<SoundSource>
getSoundSources()
Gets an immutable collection containing allSoundSource
entities on this environment.java.util.Collection<SoundSource>
getSoundSources(java.lang.String tag)
Gets an immutable collection containing allSoundSource
entities with the specified tag.Spawnpoint
getSpawnpoint(int mapId)
Gets theSpawnpoint
with the specified map ID from this environment.Spawnpoint
getSpawnpoint(java.lang.String name)
Gets theSpawnpoint
with the specified name from this environment.java.util.Collection<Spawnpoint>
getSpawnpoints()
Gets an immutable collection containing allSpawnpoint
entities on this environment.java.util.Collection<Spawnpoint>
getSpawnpoints(java.lang.String tag)
Gets an immutable collection containing allSpawnpoint
entities with the specified tag.StaticShadow
getStaticShadow(int mapId)
Gets theStaticShadow
with the specified map ID from this environment.StaticShadow
getStaticShadow(java.lang.String name)
Gets theStaticShadow
with the specified name from this environment.StaticShadowLayer
getStaticShadowLayer()
Gets the static shadow lighting layer of this environment.java.util.Collection<StaticShadow>
getStaticShadows()
Gets an immutable collection containing allStaticShadow
entities on this environment.java.util.Collection<StaticShadow>
getStaticShadows(java.lang.String tag)
Gets an immutable collection containing allStaticShadow
entities with the specified tag.Trigger
getTrigger(int mapId)
Gets theTrigger
with the specified map ID from this environment.Trigger
getTrigger(java.lang.String name)
Gets theTrigger
with the specified name from this environment.java.util.Collection<Trigger>
getTriggers()
Gets an immutable collection containing allTrigger
entities on this environment.java.util.Collection<Trigger>
getTriggers(java.lang.String tag)
Gets an immutable collection containing allTrigger
entities with the specified tag.java.util.Collection<java.lang.String>
getUsedTags()
Gets all tags that are assigned to entities on this environment.void
init()
Initializes all entities and lighting layers of this environment.Trigger
interact(ICollisionEntity source)
Attempts to interact with triggers on this environment.Trigger
interact(ICollisionEntity source, java.util.function.Predicate<Trigger> condition)
Attempts to interact with triggers on this environment.boolean
isLoaded()
Determines whether this environment has been loaded.boolean
isRendering()
void
load()
Initializes and loads this environment and all its entities.java.util.Collection<IEntity>
load(IMapObject mapObject)
Loads all entities for the specified map object.boolean
loadFromMap(int mapId)
Loads the entities from the map object with the specified map ID from the map of this environment.void
onRendered(RenderType renderType, EnvironmentRenderedListener listener)
Adds the specified environment rendered listener to receive events when this instance renders the specified renderType.static void
registerCustomEntityType(java.lang.Class<? extends IEntity> entityType)
Registers a customIEntity
implementation to support being loaded from anIMap
instance.static void
registerCustomEntityType(java.lang.String mapObjectType, java.lang.Class<? extends IEntity> entityType)
Registers a customIEntity
implementation to support being loaded from anIMap
instance.static void
registerMapObjectLoader(IMapObjectLoader mapObjectLoader)
Registers a custom loader instance that is responsible for loading and initializing entities of the defined MapObjectType.void
reloadFromMap(int mapId)
Reloads the map object with the specified map ID from the map by first removing any previously loaded entity and then loading it freshly from its map definition.void
remove(int mapId)
Removes the entity with the specified map ID from this environment and unloads is.void
remove(IEntity entity)
Removes the specified entity from this environment and unloads is.void
remove(java.lang.String name)
Removes the entity with the specified name from this environment and unloads is.void
removeAll(IEntity... entities)
Removes all specified entities from this environment.<T extends IEntity>
voidremoveAll(java.lang.Iterable<T> entities)
Removes all specified entities from this environment.void
removeEntityListener(EnvironmentEntityListener listener)
Removes the environment entity listener listener.void
removeListener(EnvironmentListener listener)
Removes the environment listener.void
removeListener(EnvironmentRenderedListener listener)
Removes the specified environment rendered listener.void
removeRenderable(IRenderable renderable)
void
render(java.awt.Graphics2D g)
Renders the visual contents of this instance onto the provided graphics context.void
setGravity(int gravity)
Sets the gravity for this particular environment.void
unload()
Unloads all entities of this environment.void
updateLighting()
Forces an update on the lighting layers for the entire map.void
updateLighting(java.awt.geom.Rectangle2D section)
Forces an update on the lighting layers for the specified section on the map.
Constructor Details
Environment
Instantiates a newEnvironment
for the specified map.- Parameters:
map
- The map that defines this environment.
Environment
public Environment(java.lang.String mapPath)Instantiates a newEnvironment
for the specified map.- Parameters:
mapPath
- The path to the map resource that defines this environment.
Method Details
registerMapObjectLoader
Registers a custom loader instance that is responsible for loading and initializing entities of the defined MapObjectType.
There can only be one loader for a particular type. Calling this method again for the same type will overwrite the previously registered loader.- Parameters:
mapObjectLoader
- The MapObjectLoader instance to be registered.- See Also:
IMapObjectLoader.getMapObjectType()
registerCustomEntityType
public static void registerCustomEntityType(java.lang.String mapObjectType, java.lang.Class<? extends IEntity> entityType)Registers a customIEntity
implementation to support being loaded from anIMap
instance. Note that the specified class needs to be accessible in a static manner. Inner classes that aren't declared statically are not supported. This is an overload of theregisterCustomEntityType(Class)
method that allows to explicitly specify theMapObjectType
without having to provide anEntityInfo
annotation containing this information.Custom entity types need to provide at least one constructor that matches the following criteria:
- has 2 parameters:
Environment, IMapObject
- has 2 parameters:
IMapObject, Environment
- has 1 parameter:
IMapObject
- has 1 parameter:
Environment
- is empty constructor
- Parameters:
mapObjectType
- The custom mapobjectType that is used byIMapObjects
to determine the target entity implementation.entityType
- The class type of the custom entity implementation.- See Also:
IMapObject.getType()
,EntityInfo.customMapObjectType()
- has 2 parameters:
registerCustomEntityType
Registers a customIEntity
implementation to support being loaded from anIMap
instance. Note that the specified class needs to be accessible in a static manner. Inner classes that aren't declared statically are not supported. This implementation uses the providedEntityInfo.customMapObjectType()
to determine for which type the specified class should be used.- Parameters:
entityType
- The class type of the custom entity implementation.- See Also:
registerCustomEntityType(String, Class)
,IMapObject.getType()
,EntityInfo.customMapObjectType()
onRendered
Adds the specified environment rendered listener to receive events when this instance renders the specified renderType.- Parameters:
renderType
- The type that defines to which render process this listener should be attached.listener
- The listener to add.
removeListener
Removes the specified environment rendered listener.- Parameters:
listener
- The listener to remove.
addListener
Adds the specified environment listener to receive events about the basic environment life-cycle.- Parameters:
listener
- The listener to add.
removeListener
Removes the environment listener.- Parameters:
listener
- The listener to remove.
addEntityListener
Adds the specified environment entity listener to receive events about entities on this environment.- Parameters:
listener
- The listener to add.
removeEntityListener
Removes the environment entity listener listener.- Parameters:
listener
- The listener to remove.
add
Adds the specified entity to the environment container. This also loads the entity (registers entity and controllers for update) if the environment has already been loaded. The entity will not be bound to a layer.- Parameters:
entity
- The entity to add to the environment.- See Also:
isLoaded()
,IEntity.loaded(Environment)
,EnvironmentEntityListener.entityAdded(IEntity)
addAll
Adds all the specified entities to the environment container.- Type Parameters:
T
- The type of the entity.- Parameters:
entities
- The entities to be added to the environment.- See Also:
add(IEntity)
,addAll(IEntity...)
,remove(IEntity)
,removeAll(Iterable)
addAll
Adds all the specified entities to the environment container.- Parameters:
entities
- The entities to be added to the environment.- See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
updateLighting
public void updateLighting()Forces an update on the lighting layers for the entire map.updateLighting
public void updateLighting(java.awt.geom.Rectangle2D section)Forces an update on the lighting layers for the specified section on the map.- Parameters:
section
- The section for which to update the lighting layers.- See Also:
getStaticShadowLayer()
,getAmbientLight()
,ColorLayer.updateSection(Rectangle2D)
add
Adds the specified instance to be rendered with the definedRenderType
whenever the environment's render pipeline is executed.This method can be used for any custom rendering that is not related to an entity, a GUI component or the map.
Note that you don't need to explicitly add an
Entity
if it implementsIRenderable
. The render engine will inherently call an entity's render method.- Parameters:
renderable
- The instance that should be rendered.renderType
- The render type that determines how the instance is processed by the environment's render pipeline.- See Also:
render(Graphics2D)
,RenderEngine.renderEntity(Graphics2D, IEntity)
build
Adds entities by the specified blueprint to this environment at the defined location.- Parameters:
blueprint
- The blueprint, defining the map object to load the entities from.x
- The x-coordinate of the location at which to spawn the entities.y
- The y-coordinate of the location at which to spawn the entities.- Returns:
- A collection with all added entities.
build
Adds entities by the specified blueprint to this environment at the defined location.- Parameters:
blueprint
- The blueprint, defining the map object to load the entities from.location
- The location at which to spawn the entities.- Returns:
- A collection with all added entities.
clear
public void clear()Clears all loaded entities and renderable instances from this environment.contains
Determines whether the environment contains the specified entity.- Parameters:
entity
- The entity to check for.- Returns:
- True if the environment contains the specified entity; otherwise false.
contains
public boolean contains(int mapId)Determines whether the environment contains any entity with the specified map ID.- Parameters:
mapId
- The map ID of the entity to check for.- Returns:
- True if the environment contains an entity with the specified map ID; otherwise false.
findCombatEntities
Attempts to find all combat entities whose hitBox intersects with the specified shape.- Parameters:
shape
- The shape to check intersection for.- Returns:
- A collection of all combat entities that intersect the specified
Shape
.
findCombatEntities
public java.util.Collection<ICombatEntity> findCombatEntities(java.awt.Shape shape, java.util.function.Predicate<ICombatEntity> condition)Attempts to find all combat entities whose hitBox intersects with the specified shape.- Parameters:
shape
- The shape to check intersection for.condition
- An additional condition that allows to specify a condition which determines if aICombatEntity
should be considered.- Returns:
- A collection of all combat entities that intersect the specified
Shape
.
findEntities
Attempts to find all entities whose bounding box intersects with the specified shape.- Parameters:
shape
- The shape to check intersection for.- Returns:
- A collection of all entities that intersect the specified
Shape
.
get
Gets the entity with the specified map ID from this environment.- Parameters:
mapId
- The map ID of the entity.- Returns:
- The entity with the specified map ID or null if no entity could be found.
get
Gets all entities with the specified map IDs from this environment.- Parameters:
mapIds
- The map IDs to search for.- Returns:
- A
List
of entities found, in the order given by the parameters.
get
Gets the strongly typed entity with the specified map ID from this environment.- Type Parameters:
T
- The type of the entity.- Parameters:
clss
- The class instance defining the type of the entity.mapId
- The map ID of the entity.- Returns:
- The strongly typed entity with the specified map ID or null if no entity could be found or if the defined type doesn't match.
get
Gets the entity with the specified name from this environment.- Parameters:
name
- The name of the entity.- Returns:
- The entity with the specified name or null if no entity could be found or if the defined type doesn't match.
get
Gets the strongly typed entity with the specified name from this environment.- Type Parameters:
T
- The type of the entity.- Parameters:
clss
- The class instance defining the type of the entity.name
- The name of the entity.- Returns:
- The strongly typed entity with the specified name or null if no entity could be found or if the defined type doesn't match.
getByTag
Gets a distinct collection of all entities with any of the specified tags.- Parameters:
tags
- The tags to search for.- Returns:
- All entities with any of the specified tags.
getByTag
public <T extends IEntity> java.util.Collection<T> getByTag(java.lang.Class<? extends T> clss, java.lang.String... tags)Gets a distinct and strongly named collection of all entities with any of the specified tags.- Type Parameters:
T
- The type of the entity.- Parameters:
clss
- The class instance defining the type of the entity.tags
- The tags to search for.- Returns:
- All entities with any of the specified tags.
getAmbientLight
Gets the ambient light instance of this environment.- Returns:
- The ambient light instance of this environment.
- See Also:
getStaticShadowLayer()
getStaticShadowLayer
Gets the static shadow lighting layer of this environment.- Returns:
- The static shadow lighting layer of this environment.
- See Also:
getAmbientLight()
getAllMapIDs
public java.util.Collection<java.lang.Integer> getAllMapIDs()Gets an immutable collection with all assigned map IDs on this environment.- Returns:
- An immutable collection with all map IDs.
getAreas
Gets an immutable collection containing allMapArea
entities on this environment.To add or remove entities, use the corresponding methods on this environment.
- Returns:
- An immutable collection with all
MapArea
entities. - See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getAreas
Gets an immutable collection containing allMapArea
entities with the specified tag.To add or remove entities, use the corresponding methods on this environment.
- Parameters:
tag
- The tag that theMapArea
entities have to provide to be returned.- Returns:
- An immutable collection with all
MapArea
entities with the specified tag. - See Also:
getAreas()
,add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getArea
Gets theMapArea
with the specified map ID from this environment.- Parameters:
mapId
- The map ID of the entity.- Returns:
- The
MapArea
with the specified map ID or null if no entity is found. - See Also:
getArea(String)
,getAreas()
getArea
Gets theMapArea
with the specified name from this environment.- Parameters:
name
- The name of the entity.- Returns:
- The
MapArea
with the specified name or null if no entity is found. - See Also:
getArea(int)
,getAreas()
getEmitters
Gets an immutable collection containing allEmitter
entities on this environment.To add or remove entities, use the corresponding methods on this environment.
- Returns:
- An immutable collection with all
Emitter
entities. - See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getEmitters
Gets an immutable collection containing allEmitter
entities with the specified tag.To add or remove entities, use the corresponding methods on this environment.
- Parameters:
tag
- The tag that theEmitter
entities have to provide to be returned.- Returns:
- An immutable collection with all
Emitter
entities with the specified tag. - See Also:
getEmitters()
,add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getEmitter
Gets theEmitter
with the specified map ID from this environment.- Parameters:
mapId
- The map ID of the entity.- Returns:
- The
Emitter
with the specified map ID or null if no entity is found. - See Also:
getEmitter(String)
,getEmitters()
getEmitter
Gets theEmitter
with the specified name from this environment.- Parameters:
name
- The name of the entity.- Returns:
- The
Emitter
with the specified name or null if no entity is found. - See Also:
getEmitter(int)
,getEmitters()
getCollisionBoxes
Gets an immutable collection containing allCollisionBox
entities on this environment.To add or remove entities, use the corresponding methods on this environment.
- Returns:
- An immutable collection with all
CollisionBox
entities. - See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getCollisionBoxes
Gets an immutable collection containing allCollisionBox
entities with the specified tag.To add or remove entities, use the corresponding methods on this environment.
- Parameters:
tag
- The tag that theCollisionBox
entities have to provide to be returned.- Returns:
- An immutable collection with all
CollisionBox
entities with the specified tag. - See Also:
getCollisionBoxes()
,add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getCollisionBox
Gets theCollisionBox
with the specified map ID from this environment.- Parameters:
mapId
- The map ID of the entity.- Returns:
- The
CollisionBox
with the specified map ID or null if no entity is found. - See Also:
getCollisionBox(String)
,getCollisionBoxes()
getCollisionBox
Gets theCollisionBox
with the specified name from this environment.- Parameters:
name
- The name of the entity.- Returns:
- The
CollisionBox
with the specified name or null if no entity is found. - See Also:
getCollisionBox(int)
,getCollisionBoxes()
getCombatEntities
Gets an immutable collection containing allICombatEntity
entities on this environment.To add or remove entities, use the corresponding methods on this environment.
- Returns:
- An immutable collection with all
ICombatEntity
entities. - See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getCombatEntities
Gets an immutable collection containing allICombatEntity
entities with the specified tag.To add or remove entities, use the corresponding methods on this environment.
- Parameters:
tag
- The tag that theICombatEntity
entities have to provide to be returned.- Returns:
- An immutable collection with all
ICombatEntity
entities with the specified tag. - See Also:
getMobileEntities()
,add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getCombatEntity
Gets theICombatEntity
with the specified map ID from this environment.- Parameters:
mapId
- The map ID of the entity.- Returns:
- The
ICombatEntity
with the specified map ID or null if no entity is found. - See Also:
getCombatEntity(String)
,getCombatEntities()
getCombatEntity
Gets theICombatEntity
with the specified name from this environment.- Parameters:
name
- The name of the entity.- Returns:
- The
ICombatEntity
with the specified name or null if no entity is found. - See Also:
getCombatEntity(int)
,getCombatEntities()
getEntities
Gets an immutable collection containing all entities on this environment.To add or remove entities, use the corresponding methods on this environment.
- Returns:
- An immutable collection with all entities.
- See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getEntities
public <T> java.util.Collection<T> getEntities(java.lang.Class<? extends T> cls)Gets all entities of the specified type on this environment.- Type Parameters:
T
- The type of the entity.- Parameters:
cls
- The class instance defining the type of the entity.- Returns:
- All entities of the specified type.
getEntities
public <T> java.util.Collection<T> getEntities(java.lang.Class<? extends T> cls, java.lang.String tag)Gets all entities of the specified type on this environment.- Type Parameters:
T
- The type of the entity.- Parameters:
cls
- The class instance defining the type of the entity.tag
- A tag that decides whether the defined entity should be included in the result.- Returns:
- All entities of the specified type.
getEntities
public <T> java.util.Collection<T> getEntities(java.lang.Class<? extends T> cls, java.util.function.Predicate<T> pred)Gets all entities of the specified type on this environment.- Type Parameters:
T
- The type of the entity.- Parameters:
cls
- The class instance defining the type of the entity.pred
- A predicate that decides whether the defined entity should be included in the result.- Returns:
- All entities of the specified type.
getEntities
Gets the entities with the specified render type that are not bound to layers.Entities are unbound from there originating
MapObjectLayer
if theirRenderType
differs from the layer'sRenderType
.- Parameters:
renderType
- The render type- Returns:
- The miscellaneous entities with the specified render type
- See Also:
IEntity.getRenderType()
,ILayer.getRenderType()
getEntities
Gets the entities that are bound to the specified layer.Entities are bound to a layer if their
RenderType
matches the layer'sRenderType
- Parameters:
layer
- The layer that the entities are bound to.- Returns:
- The entities that are bound to the specified layer.
- See Also:
IEntity.getRenderType()
,ILayer.getRenderType()
getEntitiesByLayer
Gets the entities that are bound to layer with the specified name.Entities are bound to a layer if their
RenderType
matches the layer'sRenderType
- Parameters:
name
- The name of the layer- Returns:
- The entities that are bound to the specified layer.
- See Also:
IEntity.getRenderType()
,ILayer.getRenderType()
,ILayer.getName()
getEntitiesByLayer
Gets the entities that are bound to layer with the specified layer ID.Entities are bound to a layer if their
RenderType
matches the layer'sRenderType
- Parameters:
layerId
- The id of the layer- Returns:
- The entities that are bound to the specified layer.
- See Also:
IEntity.getRenderType()
,ILayer.getRenderType()
,ILayer.getId()
getEntitiesByTag
DON'T USE THIS! THIS IS FOR ENGINE INTERNAL PURPOSES ONLY!.- Returns:
- A map with all entities by tags.
getLightSources
Gets an immutable collection containing allLightSource
entities on this environment.To add or remove entities, use the corresponding methods on this environment.
- Returns:
- An immutable collection with all
LightSource
entities. - See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getLightSources
Gets an immutable collection containing allLightSource
entities with the specified tag.To add or remove entities, use the corresponding methods on this environment.
- Parameters:
tag
- The tag that theLightSource
entities have to provide to be returned.- Returns:
- An immutable collection with all
LightSource
entities with the specified tag. - See Also:
getLightSources()
,add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getLightSource
Gets theLightSource
with the specified map ID from this environment.- Parameters:
mapId
- The map ID of the entity.- Returns:
- The
LightSource
with the specified map ID or null if no entity is found. - See Also:
getLightSource(String)
,getLightSources()
getLightSource
Gets theLightSource
with the specified name from this environment.- Parameters:
name
- The name of the entity.- Returns:
- The
LightSource
with the specified name or null if no entity is found. - See Also:
getLightSource(int)
,getLightSources()
getLocalMapId
public static int getLocalMapId()Gets the next unique local map id. (All local map ids are negative).- Returns:
- The next unique local map id.
getMap
Gets the map on which this environment is based upon.- Returns:
- The map of this environment.
getMobileEntities
Gets an immutable collection containing allIMobileEntity
instances on this environment.To add or remove entities, use the corresponding methods on this environment.
- Returns:
- An immutable collection with all
IMobileEntity
instances. - See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getMobileEntities
Gets an immutable collection containing allIMobileEntity
entities with the specified tag.To add or remove entities, use the corresponding methods on this environment.
- Parameters:
tag
- The tag that theIMobileEntity
entities have to provide to be returned.- Returns:
- An immutable collection with all
IMobileEntity
entities with the specified tag. - See Also:
getMobileEntities()
,add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getMobileEntity
Gets theIMobileEntity
with the specified map ID from this environment.- Parameters:
mapId
- The map ID of the entity.- Returns:
- The
IMobileEntity
with the specified map ID or null if no entity is found. - See Also:
getMobileEntity(String)
,getMobileEntities()
getMobileEntity
Gets theIMobileEntity
with the specified name from this environment.- Parameters:
name
- The name of the entity.- Returns:
- The
IMobileEntity
with the specified name or null if no entity is found. - See Also:
getMobileEntity(int)
,getMobileEntities()
getNextMapId
public int getNextMapId()Gets the next unique global map id.- Returns:
- The next unique global map id.
getRenderables
Gets an immutable collection containing allIRenderable
instances for the specified render type on this environment.To add or remove instances, use the corresponding methods on this environment.
- Parameters:
renderType
- The render type of the renderable instances.- Returns:
- An immutable collection with all
IRenderable
instances. - See Also:
add(IRenderable, RenderType)
,removeRenderable(IRenderable)
getProps
Gets an immutable collection containing allProp
entities on this environment.To add or remove entities, use the corresponding methods on this environment.
- Returns:
- An immutable collection with all
Prop
entities. - See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getProps
Gets an immutable collection containing allProp
entities with the specified tag.To add or remove entities, use the corresponding methods on this environment.
- Parameters:
tag
- The tag that theProp
entities have to provide to be returned.- Returns:
- An immutable collection with all
Prop
entities with the specified tag. - See Also:
getProps()
,add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getProp
Gets theProp
with the specified map ID from this environment.- Parameters:
mapId
- The map ID of the entity.- Returns:
- The
Prop
with the specified map ID or null if no entity is found. - See Also:
getProp(String)
,getProps()
getProp
Gets theProp
with the specified name from this environment.- Parameters:
name
- The name of the entity.- Returns:
- The
Prop
with the specified name or null if no entity is found. - See Also:
getProp(int)
,getProps()
getCreatures
Gets an immutable collection containing allCreature
entities on this environment.To add or remove entities, use the corresponding methods on this environment.
- Returns:
- An immutable collection with all
Creature
entities. - See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getCreatures
Gets an immutable collection containing allCreature
entities with the specified tag.To add or remove entities, use the corresponding methods on this environment.
- Parameters:
tag
- The tag that theCreature
entities have to provide to be returned.- Returns:
- An immutable collection with all
Creature
entities with the specified tag. - See Also:
getCreatures()
,add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getCreature
Gets theCreature
with the specified map ID from this environment.- Parameters:
mapId
- The map ID of the entity.- Returns:
- The
Creature
with the specified map ID or null if no entity is found. - See Also:
getCreature(String)
,getCreatures()
getCreature
Gets theCreature
with the specified name from this environment.- Parameters:
name
- The name of the entity.- Returns:
- The
Creature
with the specified name or null if no entity is found. - See Also:
getCreature(int)
,getCreatures()
getSpawnpoints
Gets an immutable collection containing allSpawnpoint
entities on this environment.To add or remove entities, use the corresponding methods on this environment.
- Returns:
- An immutable collection with all
Spawnpoint
entities. - See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getSpawnpoints
Gets an immutable collection containing allSpawnpoint
entities with the specified tag.To add or remove entities, use the corresponding methods on this environment.
- Parameters:
tag
- The tag that theSpawnpoint
entities have to provide to be returned.- Returns:
- An immutable collection with all
Spawnpoint
entities with the specified tag. - See Also:
getSpawnpoints()
,add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getSpawnpoint
Gets theSpawnpoint
with the specified map ID from this environment.- Parameters:
mapId
- The map ID of the entity.- Returns:
- The
Spawnpoint
with the specified map ID or null if no entity is found. - See Also:
getSpawnpoint(String)
,getSpawnpoints()
getSpawnpoint
Gets theSpawnpoint
with the specified name from this environment.- Parameters:
name
- The name of the entity.- Returns:
- The
Spawnpoint
with the specified name or null if no entity is found. - See Also:
getSpawnpoint(int)
,getSpawnpoints()
getSoundSources
Gets an immutable collection containing allSoundSource
entities on this environment.To add or remove entities, use the corresponding methods on this environment.
- Returns:
- An immutable collection with all
SoundSource
entities. - See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getSoundSources
Gets an immutable collection containing allSoundSource
entities with the specified tag.To add or remove entities, use the corresponding methods on this environment.
- Parameters:
tag
- The tag that theSoundSource
entities have to provide to be returned.- Returns:
- An immutable collection with all
SoundSource
entities with the specified tag. - See Also:
getSoundSources()
,add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getSoundSource
Gets theSoundSource
with the specified map ID from this environment.- Parameters:
mapId
- The map ID of the entity.- Returns:
- The
SoundSource
with the specified map ID or null if no entity is found. - See Also:
getSpawnpoint(String)
,getSpawnpoints()
getSoundSource
Gets theSoundSource
with the specified name from this environment.- Parameters:
name
- The name of the entity.- Returns:
- The
SoundSource
with the specified name or null if no entity is found. - See Also:
getSpawnpoint(int)
,getSpawnpoints()
getStaticShadows
Gets an immutable collection containing allStaticShadow
entities on this environment.To add or remove entities, use the corresponding methods on this environment.
- Returns:
- An immutable collection with all
StaticShadow
entities. - See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getStaticShadows
Gets an immutable collection containing allStaticShadow
entities with the specified tag.To add or remove entities, use the corresponding methods on this environment.
- Parameters:
tag
- The tag that theStaticShadow
entities have to provide to be returned.- Returns:
- An immutable collection with all
StaticShadow
entities with the specified tag. - See Also:
getStaticShadows()
,add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getStaticShadow
Gets theStaticShadow
with the specified map ID from this environment.- Parameters:
mapId
- The map ID of the entity.- Returns:
- The
StaticShadow
with the specified map ID or null if no entity is found. - See Also:
getStaticShadow(String)
,getStaticShadows()
getStaticShadow
Gets theStaticShadow
with the specified name from this environment.- Parameters:
name
- The name of the entity.- Returns:
- The
StaticShadow
with the specified name or null if no entity is found. - See Also:
getStaticShadow(int)
,getStaticShadows()
getTriggers
Gets an immutable collection containing allTrigger
entities on this environment.To add or remove entities, use the corresponding methods on this environment.
- Returns:
- An immutable collection with all
Trigger
entities. - See Also:
add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getTriggers
Gets an immutable collection containing allTrigger
entities with the specified tag.To add or remove entities, use the corresponding methods on this environment.
- Parameters:
tag
- The tag that theTrigger
entities have to provide to be returned.- Returns:
- An immutable collection with all
Trigger
entities with the specified tag. - See Also:
getTriggers()
,add(IEntity)
,addAll(Iterable)
,remove(IEntity)
,removeAll(Iterable)
getTrigger
Gets theTrigger
with the specified map ID from this environment.- Parameters:
mapId
- The map ID of the entity.- Returns:
- The
Trigger
with the specified map ID or null if no entity is found. - See Also:
getTrigger(String)
,getTriggers()
getTrigger
Gets theTrigger
with the specified name from this environment.- Parameters:
name
- The name of the entity.- Returns:
- The
Trigger
with the specified name or null if no entity is found. - See Also:
getTrigger(int)
,getTriggers()
getUsedTags
public java.util.Collection<java.lang.String> getUsedTags()Gets all tags that are assigned to entities on this environment.- Returns:
- All assigned tags of this environment.
getCenter
public java.awt.geom.Point2D getCenter()Gets the center location of the boundaries defined by the map of this environment.- Returns:
- The center of this environment.
- See Also:
getMap()
init
public final void init()Initializes all entities and lighting layers of this environment.isLoaded
public boolean isLoaded()Determines whether this environment has been loaded.load
public void load()Initializes and loads this environment and all its entities.loadFromMap
public boolean loadFromMap(int mapId)Loads the entities from the map object with the specified map ID from the map of this environment.- Parameters:
mapId
- The map ID of the map object.- Returns:
- True if any entity could be loaded; otherwise false.
reloadFromMap
public void reloadFromMap(int mapId)Reloads the map object with the specified map ID from the map by first removing any previously loaded entity and then loading it freshly from its map definition.- Parameters:
mapId
- The map ID of the map object.- See Also:
remove(int)
,loadFromMap(int)
load
Loads all entities for the specified map object.- Parameters:
mapObject
- The mapObject to load the entities from.- Returns:
- A collection of all loaded entities.
- See Also:
IMapObjectLoader.load(Environment, IMapObject)
interact
Attempts to interact with triggers on this environment.- Parameters:
source
- The entity that attempts to interacts with triggers.- Returns:
- The trigger that the source entity was able to interact with or null.
interact
Attempts to interact with triggers on this environment.- Parameters:
source
- The entity that attempts to interacts with triggers.condition
- The condition that determines whether a trigger can be interacted with.- Returns:
- The trigger that the entity was able to interact with or null.
- See Also:
Trigger.canTrigger(ICollisionEntity)
remove
Removes the specified entity from this environment and unloads is.- Parameters:
entity
- The entity to be removed.- See Also:
remove(int)
,remove(String)
,removeAll(Iterable)
,unload(IEntity)
,EnvironmentEntityListener.entityRemoved(IEntity)
,IEntity.removed(Environment)
,EntityListener.removed(IEntity, Environment)
remove
public void remove(int mapId)Removes the entity with the specified map ID from this environment and unloads is.- Parameters:
mapId
- The map ID of the entity to be removed.- See Also:
remove(int)
,remove(String)
,removeAll(Iterable)
,unload(IEntity)
,EnvironmentEntityListener.entityRemoved(IEntity)
,IEntity.removed(Environment)
,EntityListener.removed(IEntity, Environment)
remove
public void remove(java.lang.String name)Removes the entity with the specified name from this environment and unloads is.- Parameters:
name
- The name of the entity to be removed.- See Also:
remove(int)
,remove(String)
,removeAll(Iterable)
,unload(IEntity)
,EnvironmentEntityListener.entityRemoved(IEntity)
,IEntity.removed(Environment)
,EntityListener.removed(IEntity, Environment)
removeAll
Removes all specified entities from this environment.- Type Parameters:
T
- The type of the specified entities- Parameters:
entities
- The entities to be removed.- See Also:
remove(int)
,remove(String)
removeAll
Removes all specified entities from this environment.- Parameters:
entities
- The entities to be removed.- See Also:
remove(int)
,remove(String)
removeRenderable
render
public void render(java.awt.Graphics2D g)Description copied from interface:IRenderable
Renders the visual contents of this instance onto the provided graphics context.If an
Entity
implements this interface, this method will be called right after the entity was rendered from the environment. Allowing for a custom rendering mechanism.This interface can be implemented in general by anything that should be rendered to the game's screen.
- Specified by:
render
in interfaceIRenderable
- Parameters:
g
- The current graphics object onto which this instance will render its visual contents.- See Also:
RenderEngine.renderEntity(Graphics2D, de.gurkenlabs.litiengine.entities.IEntity)
getGravity
public int getGravity()Gets the gravity defined for this environment.- Returns:
- The gravity of this environment.
- See Also:
GameWorld.gravity()
,GameWorld.setGravity(int)
,setGravity(int)
setGravity
public void setGravity(int gravity)Sets the gravity for this particular environment.This typically only needs to be called explicitly, when the gravity is different than for other environments.
- Parameters:
gravity
- The new gravity for this environment. If 0, no gravity will be applied.- See Also:
GameWorld.gravity()
,GameWorld.setGravity(int)
,getGravity()
unload
public void unload()Unloads all entities of this environment.- See Also:
unload(IEntity)
,EnvironmentListener.unloaded(Environment)
isRendering
public boolean isRendering()