use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class CollisionBoxMapObjectLoader method load.
@Override
public Collection<IEntity> load(IEnvironment environment, IMapObject mapObject) {
if (MapObjectType.get(mapObject.getType()) != MapObjectType.COLLISIONBOX) {
throw new IllegalArgumentException("Cannot load a mapobject of the type " + mapObject.getType() + " with a loader of the type " + CollisionBoxMapObjectLoader.class);
}
boolean isObstacle = mapObject.getCustomPropertyBool(MapObjectProperty.PROP_OBSTACLE, true);
boolean isObstructingLight = mapObject.getCustomPropertyBool(MapObjectProperty.COLLISIONBOX_OBSTRUCTINGLIGHTS);
final CollisionBox col = this.createCollisionBox(mapObject, isObstacle, isObstructingLight);
loadDefaultProperties(col, mapObject);
col.setCollisionBoxWidth(col.getWidth());
col.setCollisionBoxHeight(col.getHeight());
Collection<IEntity> entities = super.load(environment, mapObject);
entities.add(col);
if (isObstructingLight) {
entities.add(new StaticShadow(col));
}
return entities;
}
use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class CreatureMapObjectLoader method load.
@Override
public Collection<IEntity> load(IEnvironment environment, IMapObject mapObject) {
if (MapObjectType.get(mapObject.getType()) != MapObjectType.CREATURE) {
throw new IllegalArgumentException("Cannot load a mapobject of the type " + mapObject.getType() + " with a loader of the type " + CreatureMapObjectLoader.class);
}
Collection<IEntity> entities = super.load(environment, mapObject);
final String spriteSheet = mapObject.getCustomProperty(MapObjectProperty.SPRITESHEETNAME);
if (spriteSheet == null) {
return entities;
}
Creature creature = this.createNewCreature(mapObject, spriteSheet, mapObject.getCustomProperty(MapObjectProperty.SPAWN_TYPE));
loadDefaultProperties(creature, mapObject);
loadCollisionProperties(creature, mapObject);
// TODO: load IMobileEntity and ICombatEntity properties
creature.setFacingDirection(mapObject.getCustomPropertyEnum(MapObjectProperty.SPAWN_DIRECTION, Direction.class, Direction.RIGHT));
entities.add(creature);
return entities;
}
use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class Environment method add.
@Override
public void add(final IEntity entity) {
if (entity == null) {
return;
}
// set local map id if none is set for the entity
if (entity.getMapId() == 0) {
entity.setMapId(this.getLocalMapId());
}
if (entity instanceof Emitter) {
Emitter emitter = (Emitter) entity;
this.getGroundRenderables().add(emitter.getGroundRenderable());
this.getOverlayRenderables().add(emitter.getOverlayRenderable());
this.emitters.add(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 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;
}
if (this.entitiesByTag.containsKey(tag)) {
this.entitiesByTag.get(tag).add(entity);
continue;
}
this.entitiesByTag.put(tag, new CopyOnWriteArrayList<>());
this.entitiesByTag.get(tag).add(entity);
}
// we need to load the new entity manually
if (this.loaded) {
this.load(entity);
}
this.entities.get(entity.getRenderType()).put(entity.getMapId(), entity);
for (Consumer<IEntity> cons : this.entityAddedConsumers) {
cons.accept(entity);
}
}
use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class Environment method load.
@Override
public void load() {
this.init();
if (this.loaded) {
return;
}
Game.getPhysicsEngine().setBounds(new Rectangle2D.Double(0, 0, this.getMap().getSizeInPixels().getWidth(), this.getMap().getSizeInPixels().getHeight()));
for (final IEntity entity : this.getEntities()) {
this.load(entity);
}
this.loaded = true;
for (final Consumer<IEnvironment> cons : this.loadedConsumers) {
cons.accept(this);
}
}
use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class Environment method remove.
@Override
public void remove(final int mapId) {
final IEntity ent = this.get(mapId);
if (ent == null) {
return;
}
this.remove(ent);
}
Aggregations