use of de.gurkenlabs.litiengine.entities.SoundSource in project litiengine by gurkenlabs.
the class DebugRenderer method renderEntityDebugInfo.
public static void renderEntityDebugInfo(final Graphics2D g, final IEntity entity) {
if (!Game.config().debug().isDebugEnabled()) {
return;
}
if (Game.config().debug().renderEntityNames()) {
drawMapId(g, entity);
}
if (Game.config().debug().renderHitBoxes() && entity instanceof ICombatEntity) {
g.setColor(Color.RED);
Game.graphics().renderOutline(g, ((ICombatEntity) entity).getHitBox());
}
if (Game.config().debug().renderBoundingBoxes()) {
g.setColor(Color.RED);
Game.graphics().renderOutline(g, entity.getBoundingBox());
if (entity instanceof SoundSource) {
final int range = ((SoundSource) entity).getRange();
final float[] dash1 = { 10f };
final BasicStroke dashed = new BasicStroke(.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
Game.graphics().renderOutline(g, new Ellipse2D.Double(entity.getBoundingBox().getCenterX() - range, entity.getBoundingBox().getCenterY() - range, range * 2d, range * 2d), dashed);
}
}
if (Game.config().debug().renderCollisionBoxes() && entity instanceof ICollisionEntity) {
final ICollisionEntity collisionEntity = (ICollisionEntity) entity;
g.setColor(collisionEntity.hasCollision() ? Color.RED : Color.ORANGE);
Game.graphics().renderOutline(g, collisionEntity.getCollisionBox());
}
final EntityRenderEvent event = new EntityRenderEvent(g, entity);
for (EntityRenderedListener listener : entityDebugListeners) {
listener.rendered(event);
}
}
use of de.gurkenlabs.litiengine.entities.SoundSource in project litiengine by gurkenlabs.
the class SoundSourceMapObjectLoader method load.
@Override
public Collection<IEntity> load(Environment environment, IMapObject mapObject) {
Collection<IEntity> entities = new ArrayList<>();
if (!this.isMatchingType(mapObject)) {
return entities;
}
final SoundSource sound = this.createSoundSource(mapObject);
loadDefaultProperties(sound, mapObject);
entities.add(sound);
return entities;
}
use of de.gurkenlabs.litiengine.entities.SoundSource 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.SoundSource 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.SoundSource in project litiengine by gurkenlabs.
the class SoundSourceMapObjectLoader method createSoundSource.
protected SoundSource createSoundSource(IMapObject mapObject) {
SoundSource sound = new SoundSource();
sound.setSound(mapObject.getStringValue(MapObjectProperty.SOUND_NAME));
sound.setVolume(mapObject.getFloatValue(MapObjectProperty.SOUND_VOLUME));
sound.setLoop(mapObject.getBoolValue(MapObjectProperty.SOUND_LOOP));
sound.setRange(mapObject.getIntValue(MapObjectProperty.SOUND_RANGE));
return sound;
}
Aggregations