use of de.gurkenlabs.litiengine.entities.StaticShadow in project litiengine by gurkenlabs.
the class StaticShadowLayer method renderSection.
@Override
protected void renderSection(Graphics2D g, Rectangle2D section) {
final Color color = this.getColor();
g.setColor(color);
// check if the collision boxes have shadows. if so, determine which
// shadow is needed, create the shape and add it to the
// list of static shadows.
final Area ar = new Area();
for (final StaticShadow staticShadow : this.getEnvironment().getStaticShadows()) {
if (!staticShadow.getBoundingBox().intersects(section) || staticShadow.getShadowType() == StaticShadowType.NONE) {
continue;
}
final Area staticShadowArea = staticShadow.getArea();
ar.add(staticShadowArea);
}
ar.transform(AffineTransform.getTranslateInstance(-section.getX(), -section.getY()));
g.fill(ar);
}
use of de.gurkenlabs.litiengine.entities.StaticShadow in project litiengine by gurkenlabs.
the class Environment method remove.
/**
* Removes the specified entity from this environment and unloads is.
*
* @param entity
* The entity to be removed.
*
* @see #remove(int)
* @see #remove(String)
* @see #removeAll(Iterable)
* @see #unload(IEntity)
* @see EnvironmentEntityListener#entityRemoved(IEntity)
* @see IEntity#removed(Environment)
* @see EntityListener#removed(IEntity, Environment)
*/
public void remove(final IEntity entity) {
if (entity == null) {
return;
}
this.allEntities.remove(entity.getMapId());
Iterator<List<IEntity>> iter = this.layerEntities.values().iterator();
while (iter.hasNext()) {
List<IEntity> layer = iter.next();
if (layer.remove(entity) && layer.isEmpty()) {
iter.remove();
}
}
if (this.miscEntities.get(entity.getRenderType()) != null) {
this.miscEntities.get(entity.getRenderType()).values().remove(entity);
}
for (String tag : entity.getTags()) {
if (this.getEntitiesByTag().containsKey(tag)) {
this.getEntitiesByTag().get(tag).remove(entity);
if (this.getEntitiesByTag().get(tag).isEmpty()) {
this.getEntitiesByTag().remove(tag);
}
}
}
if (entity instanceof Emitter) {
Emitter emitter = (Emitter) entity;
this.removeEmitter(emitter);
}
if (entity instanceof MapArea) {
this.mapAreas.remove(entity);
}
if (entity instanceof Prop) {
this.props.remove(entity);
}
if (entity instanceof Creature) {
this.creatures.remove(entity);
}
if (entity instanceof CollisionBox) {
this.colliders.remove(entity);
this.staticShadows.removeIf(x -> x.getOrigin() != null && x.getOrigin().equals(entity));
}
if (entity instanceof LightSource) {
this.lightSources.remove(entity);
this.updateLighting(entity);
}
if (entity instanceof Trigger) {
this.triggers.remove(entity);
}
if (entity instanceof Spawnpoint) {
this.spawnPoints.remove(entity);
}
if (entity instanceof SoundSource) {
this.soundSources.remove(entity);
}
if (entity instanceof StaticShadow) {
this.staticShadows.remove(entity);
this.updateLighting(entity);
}
if (entity instanceof IMobileEntity) {
this.mobileEntities.values().remove(entity);
}
if (entity instanceof ICombatEntity) {
this.combatEntities.values().remove(entity);
}
this.unload(entity);
this.fireEntityEvent(l -> l.entityRemoved(entity));
}
use of de.gurkenlabs.litiengine.entities.StaticShadow in project litiengine by gurkenlabs.
the class Environment method addEntity.
private void addEntity(final IEntity entity) {
int desiredID = entity.getMapId();
// assign local map id if the entity's mapID is invalid
if (desiredID == 0 || this.allEntities.keySet().contains(desiredID)) {
entity.setMapId(getLocalMapId());
log.fine(() -> String.format("Entity [%s] was assigned a local mapID because #%d was already taken or invalid.", entity, desiredID));
}
if (entity instanceof Emitter) {
Emitter emitter = (Emitter) entity;
this.addEmitter(emitter);
}
if (entity instanceof ICombatEntity) {
this.combatEntities.put(entity.getMapId(), (ICombatEntity) entity);
}
if (entity instanceof IMobileEntity) {
this.mobileEntities.put(entity.getMapId(), (IMobileEntity) entity);
}
if (entity instanceof Prop) {
this.props.add((Prop) entity);
}
if (entity instanceof Creature) {
this.creatures.add((Creature) entity);
}
if (entity instanceof CollisionBox) {
this.colliders.add((CollisionBox) entity);
}
if (entity instanceof LightSource) {
this.lightSources.add((LightSource) entity);
}
if (entity instanceof Trigger) {
this.triggers.add((Trigger) entity);
}
if (entity instanceof Spawnpoint) {
this.spawnPoints.add((Spawnpoint) entity);
}
if (entity instanceof SoundSource) {
this.soundSources.add((SoundSource) entity);
}
if (entity instanceof StaticShadow) {
this.staticShadows.add((StaticShadow) entity);
} else if (entity instanceof MapArea) {
this.mapAreas.add((MapArea) entity);
}
for (String rawTag : entity.getTags()) {
if (rawTag == null) {
continue;
}
final String tag = rawTag.trim().toLowerCase();
if (tag.isEmpty()) {
continue;
}
this.getEntitiesByTag().computeIfAbsent(tag, t -> new CopyOnWriteArrayList<>()).add(entity);
}
// we need to load the new entity manually
if (this.loaded) {
this.load(entity);
}
this.allEntities.put(entity.getMapId(), entity);
}
use of de.gurkenlabs.litiengine.entities.StaticShadow in project litiengine by gurkenlabs.
the class StaticShadowMapObjectLoader method load.
@Override
public Collection<IEntity> load(Environment environment, IMapObject mapObject) {
Collection<IEntity> entities = new ArrayList<>();
if (!this.isMatchingType(mapObject)) {
return entities;
}
StaticShadowType type = mapObject.getEnumValue(MapObjectProperty.SHADOW_TYPE, StaticShadowType.class, StaticShadowType.DOWN);
int offset = mapObject.getIntValue(MapObjectProperty.SHADOW_OFFSET, StaticShadow.DEFAULT_OFFSET);
StaticShadow shadow = this.createStaticShadow(mapObject, type, offset);
loadDefaultProperties(shadow, mapObject);
shadow.setOffset(offset);
entities.add(shadow);
return entities;
}
Aggregations