Search in sources :

Example 6 with IEntity

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;
}
Also used : StaticShadow(de.gurkenlabs.litiengine.graphics.StaticShadow) IEntity(de.gurkenlabs.litiengine.entities.IEntity) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox)

Example 7 with IEntity

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;
}
Also used : Creature(de.gurkenlabs.litiengine.entities.Creature) IEntity(de.gurkenlabs.litiengine.entities.IEntity) Direction(de.gurkenlabs.litiengine.entities.Direction)

Example 8 with IEntity

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);
    }
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) Creature(de.gurkenlabs.litiengine.entities.Creature) Prop(de.gurkenlabs.litiengine.entities.Prop) IEntity(de.gurkenlabs.litiengine.entities.IEntity) MapArea(de.gurkenlabs.litiengine.environment.tilemap.MapArea) Trigger(de.gurkenlabs.litiengine.entities.Trigger) StaticShadow(de.gurkenlabs.litiengine.graphics.StaticShadow) IMobileEntity(de.gurkenlabs.litiengine.entities.IMobileEntity) LightSource(de.gurkenlabs.litiengine.graphics.LightSource) Spawnpoint(de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox)

Example 9 with IEntity

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);
    }
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) Rectangle2D(java.awt.geom.Rectangle2D)

Example 10 with IEntity

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);
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity)

Aggregations

IEntity (de.gurkenlabs.litiengine.entities.IEntity)26 Test (org.junit.jupiter.api.Test)9 IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)6 Trigger (de.gurkenlabs.litiengine.entities.Trigger)5 Dimension (java.awt.Dimension)5 Point (java.awt.Point)5 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)4 ICombatEntity (de.gurkenlabs.litiengine.entities.ICombatEntity)4 Prop (de.gurkenlabs.litiengine.entities.Prop)4 MapArea (de.gurkenlabs.litiengine.environment.tilemap.MapArea)4 LightSource (de.gurkenlabs.litiengine.graphics.LightSource)4 StaticShadow (de.gurkenlabs.litiengine.graphics.StaticShadow)4 Creature (de.gurkenlabs.litiengine.entities.Creature)3 Spawnpoint (de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint)3 Direction (de.gurkenlabs.litiengine.entities.Direction)2 IMobileEntity (de.gurkenlabs.litiengine.entities.IMobileEntity)2 Emitter (de.gurkenlabs.litiengine.graphics.particles.Emitter)2 Rectangle2D (java.awt.geom.Rectangle2D)2 Consumer (java.util.function.Consumer)2 AttributeModifier (de.gurkenlabs.litiengine.attributes.AttributeModifier)1