Search in sources :

Example 1 with StaticShadow

use of de.gurkenlabs.litiengine.graphics.StaticShadow in project litiengine by gurkenlabs.

the class EnvironmentTests method testStaticShadow.

@Test
public void testStaticShadow() {
    StaticShadow testShadow = new StaticShadow(0, 0, 1, 1, StaticShadowType.NONE);
    testShadow.setMapId(1);
    testShadow.setName("test");
    this.testEnvironment.add(testShadow);
    assertNotNull(this.testEnvironment.getStaticShadow(1));
    assertNotNull(this.testEnvironment.getStaticShadow("test"));
    assertEquals(1, this.testEnvironment.getByType(StaticShadow.class).size());
    assertEquals(1, this.testEnvironment.getEntities().size());
    this.testEnvironment.remove(testShadow);
    assertNull(this.testEnvironment.getStaticShadow(1));
    assertNull(this.testEnvironment.getStaticShadow("test"));
    assertEquals(0, this.testEnvironment.getByType(StaticShadow.class).size());
    assertEquals(0, this.testEnvironment.getEntities().size());
}
Also used : StaticShadow(de.gurkenlabs.litiengine.graphics.StaticShadow) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with StaticShadow

use of de.gurkenlabs.litiengine.graphics.StaticShadow 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 3 with StaticShadow

use of de.gurkenlabs.litiengine.graphics.StaticShadow in project litiengine by gurkenlabs.

the class Environment method load.

/**
 * Loads the specified entiy by performing the following steps:
 * <ol>
 * <li>add to physics engine</li>
 * <li>register entity for update</li>
 * <li>register animation controller for update</li>
 * <li>register movement controller for update</li>
 * <li>register AI controller for update</li>
 * </ol>
 *
 * @param entity
 */
private void load(final IEntity entity) {
    // 1. add to physics engine
    this.loadPhysicsEntity(entity);
    // 2. register for update or activate
    this.loadUpdatableOrEmitterEntity(entity);
    // 3. register animation controller for update
    final IAnimationController animation = Game.getEntityControllerManager().getAnimationController(entity);
    if (animation != null) {
        Game.getLoop().attach(animation);
    }
    // 4. register movement controller for update
    if (entity instanceof IMobileEntity) {
        final IMovementController<? extends IMobileEntity> movementController = Game.getEntityControllerManager().getMovementController((IMobileEntity) entity);
        if (movementController != null) {
            Game.getLoop().attach(movementController);
        }
    }
    // 5. register ai controller for update
    final IEntityController<? extends IEntity> controller = Game.getEntityControllerManager().getAIController(entity);
    if (controller != null) {
        Game.getLoop().attach(controller);
    }
    if (entity instanceof LightSource || entity instanceof StaticShadow) {
        this.updateColorLayers(entity);
    }
}
Also used : StaticShadow(de.gurkenlabs.litiengine.graphics.StaticShadow) IMobileEntity(de.gurkenlabs.litiengine.entities.IMobileEntity) IAnimationController(de.gurkenlabs.litiengine.graphics.animation.IAnimationController) LightSource(de.gurkenlabs.litiengine.graphics.LightSource)

Example 4 with StaticShadow

use of de.gurkenlabs.litiengine.graphics.StaticShadow 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 5 with StaticShadow

use of de.gurkenlabs.litiengine.graphics.StaticShadow in project litiengine by gurkenlabs.

the class StaticShadowMapObjectLoader method load.

@Override
public Collection<IEntity> load(IEnvironment environment, IMapObject mapObject) {
    if (MapObjectType.get(mapObject.getType()) != MapObjectType.STATICSHADOW) {
        throw new IllegalArgumentException("Cannot load a mapobject of the type " + mapObject.getType() + " with a loader of the type " + MapAreaMapObjectLoader.class);
    }
    Collection<IEntity> entities = super.load(environment, mapObject);
    StaticShadowType type = mapObject.getCustomPropertyEnum(MapObjectProperty.SHADOW_TYPE, StaticShadowType.class, StaticShadowType.DOWN);
    int offset = mapObject.getCustomPropertyInt(MapObjectProperty.SHADOW_OFFSET, StaticShadow.DEFAULT_OFFSET);
    StaticShadow shadow = this.createStaticShadow(mapObject, type, offset);
    loadDefaultProperties(shadow, mapObject);
    shadow.setOffset(offset);
    entities.add(shadow);
    return entities;
}
Also used : StaticShadowType(de.gurkenlabs.litiengine.graphics.StaticShadowType) StaticShadow(de.gurkenlabs.litiengine.graphics.StaticShadow) IEntity(de.gurkenlabs.litiengine.entities.IEntity)

Aggregations

StaticShadow (de.gurkenlabs.litiengine.graphics.StaticShadow)7 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)4 IEntity (de.gurkenlabs.litiengine.entities.IEntity)4 LightSource (de.gurkenlabs.litiengine.graphics.LightSource)4 Creature (de.gurkenlabs.litiengine.entities.Creature)3 IMobileEntity (de.gurkenlabs.litiengine.entities.IMobileEntity)3 Prop (de.gurkenlabs.litiengine.entities.Prop)3 Trigger (de.gurkenlabs.litiengine.entities.Trigger)3 MapArea (de.gurkenlabs.litiengine.environment.tilemap.MapArea)3 Spawnpoint (de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint)3 Emitter (de.gurkenlabs.litiengine.graphics.particles.Emitter)3 ICombatEntity (de.gurkenlabs.litiengine.entities.ICombatEntity)2 StaticShadowType (de.gurkenlabs.litiengine.graphics.StaticShadowType)1 IAnimationController (de.gurkenlabs.litiengine.graphics.animation.IAnimationController)1 IconTreeListItem (de.gurkenlabs.utiliti.swing.IconTreeListItem)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1