Class Environment

java.lang.Object
de.gurkenlabs.litiengine.environment.Environment
All Implemented Interfaces:
IRenderable

public final class Environment extends Object implements IRenderable
  • Constructor Details

    • Environment

      public Environment(IMap map)
      Instantiates a new Environment for the specified map.
      Parameters:
      map - The map that defines this environment.
    • Environment

      public Environment(String mapPath)
      Instantiates a new Environment for the specified map.
      Parameters:
      mapPath - The path to the map resource that defines this environment.
  • Method Details

    • registerMapObjectLoader

      public static void registerMapObjectLoader(IMapObjectLoader mapObjectLoader)
      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:
    • registerCustomEntityType

      public static void registerCustomEntityType(String mapObjectType, Class<? extends IEntity> entityType)
      Registers a custom IEntity implementation to support being loaded from an IMap 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 the registerCustomEntityType(Class) method that allows to explicitly specify the MapObjectType without having to provide an EntityInfo 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 by IMapObjects to determine the target entity implementation.
      entityType - The class type of the custom entity implementation.
      See Also:
    • registerCustomEntityType

      public static void registerCustomEntityType(Class<? extends IEntity> entityType)
      Registers a custom IEntity implementation to support being loaded from an IMap 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 provided EntityInfo.customMapObjectType() to determine for which type the specified class should be used.

      Parameters:
      entityType - The class type of the custom entity implementation.
      See Also:
    • onRendered

      public void onRendered(RenderType renderType, EnvironmentRenderedListener listener)
      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

      public void removeListener(EnvironmentRenderedListener listener)
      Removes the specified environment rendered listener.
      Parameters:
      listener - The listener to remove.
    • addListener

      public void addListener(EnvironmentListener listener)
      Adds the specified environment listener to receive events about the basic environment life-cycle.
      Parameters:
      listener - The listener to add.
    • removeListener

      public void removeListener(EnvironmentListener listener)
      Removes the environment listener.
      Parameters:
      listener - The listener to remove.
    • addEntityListener

      public void addEntityListener(EnvironmentEntityListener listener)
      Adds the specified environment entity listener to receive events about entities on this environment.
      Parameters:
      listener - The listener to add.
    • removeEntityListener

      public void removeEntityListener(EnvironmentEntityListener listener)
      Removes the environment entity listener listener.
      Parameters:
      listener - The listener to remove.
    • add

      public void add(IEntity entity)
      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:
    • addAll

      public <T extends IEntity> void addAll(Iterable<T> entities)
      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:
    • addAll

      public void addAll(IEntity... entities)
      Adds all the specified entities to the environment container.
      Parameters:
      entities - The entities to be added to the environment.
      See Also:
    • updateLighting

      public void updateLighting()
      Forces an update on the lighting layers for the entire map.
      See Also:
    • updateLighting

      public void updateLighting(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:
    • add

      public void add(IRenderable renderable, RenderType renderType)
      Adds the specified instance to be rendered with the defined RenderType 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 implements IRenderable. 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:
    • build

      public Collection<IEntity> build(Blueprint blueprint, double x, double y)
      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

      public Collection<IEntity> build(Blueprint blueprint, Point2D location)
      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

      public boolean contains(IEntity entity)
      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

      public Collection<ICombatEntity> findCombatEntities(Shape shape)
      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 Collection<ICombatEntity> findCombatEntities(Shape shape, 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 a ICombatEntity should be considered.
      Returns:
      A collection of all combat entities that intersect the specified Shape.
    • findEntities

      public Collection<IEntity> findEntities(Shape shape)
      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

      public IEntity get(int mapId)
      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

      public List<IEntity> get(int... mapIds)
      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

      public <T extends IEntity> T get(Class<T> clss, int mapId)
      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

      public IEntity get(String name)
      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

      public <T extends IEntity> T get(Class<T> clss, String name)
      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

      public Collection<IEntity> getByTag(String... tags)
      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> Collection<T> getByTag(Class<? extends T> clss, 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

      public AmbientLight getAmbientLight()
      Gets the ambient light instance of this environment.
      Returns:
      The ambient light instance of this environment.
      See Also:
    • getStaticShadowLayer

      public StaticShadowLayer getStaticShadowLayer()
      Gets the static shadow lighting layer of this environment.
      Returns:
      The static shadow lighting layer of this environment.
      See Also:
    • getAllMapIDs

      public Collection<Integer> getAllMapIDs()
      Gets an immutable collection with all assigned map IDs on this environment.
      Returns:
      An immutable collection with all map IDs.
    • getAreas

      public Collection<MapArea> getAreas()
      Gets an immutable collection containing all MapArea 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:
    • getAreas

      public Collection<MapArea> getAreas(String tag)
      Gets an immutable collection containing all MapArea entities with the specified tag.

      To add or remove entities, use the corresponding methods on this environment.

      Parameters:
      tag - The tag that the MapArea entities have to provide to be returned.
      Returns:
      An immutable collection with all MapArea entities with the specified tag.
      See Also:
    • getArea

      public MapArea getArea(int mapId)
      Gets the MapArea 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

      public MapArea getArea(String name)
      Gets the MapArea 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:
    • getEmitters

      public Collection<Emitter> getEmitters()
      Gets an immutable collection containing all Emitter 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:
    • getEmitters

      public Collection<Emitter> getEmitters(String tag)
      Gets an immutable collection containing all Emitter entities with the specified tag.

      To add or remove entities, use the corresponding methods on this environment.

      Parameters:
      tag - The tag that the Emitter entities have to provide to be returned.
      Returns:
      An immutable collection with all Emitter entities with the specified tag.
      See Also:
    • getEmitter

      public Emitter getEmitter(int mapId)
      Gets the Emitter 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

      public Emitter getEmitter(String name)
      Gets the Emitter 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:
    • getCollisionBoxes

      public Collection<CollisionBox> getCollisionBoxes()
      Gets an immutable collection containing all CollisionBox 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:
    • getCollisionBoxes

      public Collection<CollisionBox> getCollisionBoxes(String tag)
      Gets an immutable collection containing all CollisionBox entities with the specified tag.

      To add or remove entities, use the corresponding methods on this environment.

      Parameters:
      tag - The tag that the CollisionBox entities have to provide to be returned.
      Returns:
      An immutable collection with all CollisionBox entities with the specified tag.
      See Also:
    • getCollisionBox

      public CollisionBox getCollisionBox(int mapId)
      Gets the CollisionBox 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

      public CollisionBox getCollisionBox(String name)
      Gets the CollisionBox 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:
    • getCombatEntities

      public Collection<ICombatEntity> getCombatEntities()
      Gets an immutable collection containing all ICombatEntity 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:
    • getCombatEntities

      public Collection<ICombatEntity> getCombatEntities(String tag)
      Gets an immutable collection containing all ICombatEntity entities with the specified tag.

      To add or remove entities, use the corresponding methods on this environment.

      Parameters:
      tag - The tag that the ICombatEntity entities have to provide to be returned.
      Returns:
      An immutable collection with all ICombatEntity entities with the specified tag.
      See Also:
    • getCombatEntity

      public ICombatEntity getCombatEntity(int mapId)
      Gets the ICombatEntity 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

      public ICombatEntity getCombatEntity(String name)
      Gets the ICombatEntity 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:
    • getEntities

      public Collection<IEntity> 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:
    • getEntities

      public <T> Collection<T> getEntities(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> Collection<T> getEntities(Class<? extends T> cls, 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> Collection<T> getEntities(Class<? extends T> cls, 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

      public Collection<IEntity> getEntities(RenderType renderType)
      Gets the entities with the specified render type that are not bound to layers.

      Entities are unbound from there originating MapObjectLayer if their RenderType differs from the layer's RenderType.

      Parameters:
      renderType - The render type
      Returns:
      The miscellaneous entities with the specified render type
      See Also:
    • getEntities

      public Collection<IEntity> getEntities(IMapObjectLayer layer)
      Gets the entities that are bound to the specified layer.

      Entities are bound to a layer if their RenderType matches the layer's RenderType

      Parameters:
      layer - The layer that the entities are bound to.
      Returns:
      The entities that are bound to the specified layer.
      See Also:
    • getEntitiesByLayer

      public Collection<IEntity> getEntitiesByLayer(String name)
      Gets the entities that are bound to layer with the specified name.

      Entities are bound to a layer if their RenderType matches the layer's RenderType

      Parameters:
      name - The name of the layer
      Returns:
      The entities that are bound to the specified layer.
      See Also:
    • getEntitiesByLayer

      public Collection<IEntity> getEntitiesByLayer(int layerId)
      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's RenderType

      Parameters:
      layerId - The id of the layer
      Returns:
      The entities that are bound to the specified layer.
      See Also:
    • getEntitiesByTag

      public Map<String,Collection<IEntity>> getEntitiesByTag()
      DON'T USE THIS! THIS IS FOR ENGINE INTERNAL PURPOSES ONLY!.
      Returns:
      A map with all entities by tags.
    • getLightSources

      public Collection<LightSource> getLightSources()
      Gets an immutable collection containing all LightSource 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:
    • getLightSources

      public Collection<LightSource> getLightSources(String tag)
      Gets an immutable collection containing all LightSource entities with the specified tag.

      To add or remove entities, use the corresponding methods on this environment.

      Parameters:
      tag - The tag that the LightSource entities have to provide to be returned.
      Returns:
      An immutable collection with all LightSource entities with the specified tag.
      See Also:
    • getLightSource

      public LightSource getLightSource(int mapId)
      Gets the LightSource 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

      public LightSource getLightSource(String name)
      Gets the LightSource 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:
    • 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

      public IMap getMap()
      Gets the map on which this environment is based upon.
      Returns:
      The map of this environment.
    • getMobileEntities

      public Collection<IMobileEntity> getMobileEntities()
      Gets an immutable collection containing all IMobileEntity 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:
    • getMobileEntities

      public Collection<IMobileEntity> getMobileEntities(String tag)
      Gets an immutable collection containing all IMobileEntity entities with the specified tag.

      To add or remove entities, use the corresponding methods on this environment.

      Parameters:
      tag - The tag that the IMobileEntity entities have to provide to be returned.
      Returns:
      An immutable collection with all IMobileEntity entities with the specified tag.
      See Also:
    • getMobileEntity

      public IMobileEntity getMobileEntity(int mapId)
      Gets the IMobileEntity 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

      public IMobileEntity getMobileEntity(String name)
      Gets the IMobileEntity 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:
    • getNextMapId

      public int getNextMapId()
      Gets the next unique global map id.
      Returns:
      The next unique global map id.
    • getRenderables

      public Collection<IRenderable> getRenderables(RenderType renderType)
      Gets an immutable collection containing all IRenderable 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:
    • getProps

      public Collection<Prop> getProps()
      Gets an immutable collection containing all Prop 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:
    • getProps

      public Collection<Prop> getProps(String tag)
      Gets an immutable collection containing all Prop entities with the specified tag.

      To add or remove entities, use the corresponding methods on this environment.

      Parameters:
      tag - The tag that the Prop entities have to provide to be returned.
      Returns:
      An immutable collection with all Prop entities with the specified tag.
      See Also:
    • getProp

      public Prop getProp(int mapId)
      Gets the Prop 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

      public Prop getProp(String name)
      Gets the Prop 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:
    • getCreatures

      public Collection<Creature> getCreatures()
      Gets an immutable collection containing all Creature 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:
    • getCreatures

      public Collection<Creature> getCreatures(String tag)
      Gets an immutable collection containing all Creature entities with the specified tag.

      To add or remove entities, use the corresponding methods on this environment.

      Parameters:
      tag - The tag that the Creature entities have to provide to be returned.
      Returns:
      An immutable collection with all Creature entities with the specified tag.
      See Also:
    • getCreature

      public Creature getCreature(int mapId)
      Gets the Creature 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

      public Creature getCreature(String name)
      Gets the Creature 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:
    • getSpawnpoints

      public Collection<Spawnpoint> getSpawnpoints()
      Gets an immutable collection containing all Spawnpoint 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:
    • getSpawnpoints

      public Collection<Spawnpoint> getSpawnpoints(String tag)
      Gets an immutable collection containing all Spawnpoint entities with the specified tag.

      To add or remove entities, use the corresponding methods on this environment.

      Parameters:
      tag - The tag that the Spawnpoint entities have to provide to be returned.
      Returns:
      An immutable collection with all Spawnpoint entities with the specified tag.
      See Also:
    • getSpawnpoint

      public Spawnpoint getSpawnpoint(int mapId)
      Gets the Spawnpoint 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

      public Spawnpoint getSpawnpoint(String name)
      Gets the Spawnpoint 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:
    • getSoundSources

      public Collection<SoundSource> getSoundSources()
      Gets an immutable collection containing all SoundSource 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:
    • getSoundSources

      public Collection<SoundSource> getSoundSources(String tag)
      Gets an immutable collection containing all SoundSource entities with the specified tag.

      To add or remove entities, use the corresponding methods on this environment.

      Parameters:
      tag - The tag that the SoundSource entities have to provide to be returned.
      Returns:
      An immutable collection with all SoundSource entities with the specified tag.
      See Also:
    • getSoundSource

      public SoundSource getSoundSource(int mapId)
      Gets the SoundSource 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:
    • getSoundSource

      public SoundSource getSoundSource(String name)
      Gets the SoundSource 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:
    • getStaticShadows

      public Collection<StaticShadow> getStaticShadows()
      Gets an immutable collection containing all StaticShadow 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:
    • getStaticShadows

      public Collection<StaticShadow> getStaticShadows(String tag)
      Gets an immutable collection containing all StaticShadow entities with the specified tag.

      To add or remove entities, use the corresponding methods on this environment.

      Parameters:
      tag - The tag that the StaticShadow entities have to provide to be returned.
      Returns:
      An immutable collection with all StaticShadow entities with the specified tag.
      See Also:
    • getStaticShadow

      public StaticShadow getStaticShadow(int mapId)
      Gets the StaticShadow 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

      public StaticShadow getStaticShadow(String name)
      Gets the StaticShadow 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:
    • getTriggers

      public Collection<Trigger> getTriggers()
      Gets an immutable collection containing all Trigger 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:
    • getTriggers

      public Collection<Trigger> getTriggers(String tag)
      Gets an immutable collection containing all Trigger entities with the specified tag.

      To add or remove entities, use the corresponding methods on this environment.

      Parameters:
      tag - The tag that the Trigger entities have to provide to be returned.
      Returns:
      An immutable collection with all Trigger entities with the specified tag.
      See Also:
    • getTrigger

      public Trigger getTrigger(int mapId)
      Gets the Trigger 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

      public Trigger getTrigger(String name)
      Gets the Trigger 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:
    • getUsedTags

      public Collection<String> getUsedTags()
      Gets all tags that are assigned to entities on this environment.
      Returns:
      All assigned tags of this environment.
    • getCenter

      public Point2D getCenter()
      Gets the center location of the boundaries defined by the map of this environment.
      Returns:
      The center of this environment.
      See Also:
    • init

      public final void init()
      Initializes all entities and lighting layers of this environment.
      See Also:
    • isLoaded

      public boolean isLoaded()
      Determines whether this environment has been loaded.
      Returns:
      True if this environment has been loaded; otherwise false.
      See Also:
    • load

      public void load()
      Initializes and loads this environment and all its entities.
      See Also:
    • 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:
    • load

      public Collection<IEntity> load(IMapObject mapObject)
      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:
    • interact

      public Trigger interact(ICollisionEntity source)
      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

      public Trigger interact(ICollisionEntity source, Predicate<Trigger> condition)
      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:
    • remove

      public void remove(IEntity entity)
      Removes the specified entity from this environment and unloads is.
      Parameters:
      entity - The entity to be removed.
      See Also:
    • 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

      public void remove(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:
    • removeAll

      public <T extends IEntity> void removeAll(Iterable<T> entities)
      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:
    • removeAll

      public void removeAll(IEntity... entities)
      Removes all specified entities from this environment.
      Parameters:
      entities - The entities to be removed.
      See Also:
    • removeRenderable

      public void removeRenderable(IRenderable renderable)
    • render

      public void render(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 interface IRenderable
      Parameters:
      g - The current graphics object onto which this instance will render its visual contents.
      See Also:
    • getGravity

      public int getGravity()
      Gets the gravity defined for this environment.
      Returns:
      The gravity of this environment.
      See Also:
    • 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:
    • unload

      public void unload()
      Unloads all entities of this environment.
      See Also:
    • isRendering

      public boolean isRendering()