Search in sources :

Example 11 with IEntity

use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.

the class PropMapObjectLoader method load.

@Override
public Collection<IEntity> load(IEnvironment environment, IMapObject mapObject) {
    if (MapObjectType.get(mapObject.getType()) != MapObjectType.PROP) {
        throw new IllegalArgumentException("Cannot load a mapobject of the type " + mapObject.getType() + " with a loader of the type " + PropMapObjectLoader.class);
    }
    final Prop prop = this.createNewProp(mapObject, mapObject.getCustomProperty(MapObjectProperty.SPRITESHEETNAME));
    loadDefaultProperties(prop, mapObject);
    loadCollisionProperties(prop, mapObject);
    final Material material = mapObject.getCustomProperty(MapObjectProperty.PROP_MATERIAL) == null ? Material.UNDEFINED : Material.valueOf(mapObject.getCustomProperty(MapObjectProperty.PROP_MATERIAL));
    prop.setMaterial(material);
    prop.setObstacle(mapObject.getCustomPropertyBool(MapObjectProperty.PROP_OBSTACLE));
    final Rotation rotation = mapObject.getCustomProperty(MapObjectProperty.PROP_ROTATION) == null ? Rotation.NONE : Rotation.valueOf(mapObject.getCustomProperty(MapObjectProperty.PROP_ROTATION));
    prop.setSpriteRotation(rotation);
    prop.setIndestructible(mapObject.getCustomPropertyBool(MapObjectProperty.PROP_INDESTRUCTIBLE));
    AttributeModifier<Integer> mod = new AttributeModifier<>(Modification.SET, mapObject.getCustomPropertyInt(MapObjectProperty.HEALTH));
    prop.getAttributes().getHealth().modifyMaxBaseValue(mod);
    prop.getAttributes().getHealth().modifyBaseValue(mod);
    prop.setAddShadow(mapObject.getCustomPropertyBool(MapObjectProperty.PROP_ADDSHADOW));
    prop.setFlipHorizontally(mapObject.getCustomPropertyBool(MapObjectProperty.PROP_FLIPHORIZONTALLY));
    prop.setFlipVertically(mapObject.getCustomPropertyBool(MapObjectProperty.PROP_FLIPVERTICALLY));
    prop.setScaling(mapObject.getCustomPropertyBool(MapObjectProperty.PROP_SCALE));
    prop.setTeam(mapObject.getCustomPropertyInt(MapObjectProperty.TEAM));
    Collection<IEntity> entities = super.load(environment, mapObject);
    entities.add(prop);
    return entities;
}
Also used : Prop(de.gurkenlabs.litiengine.entities.Prop) IEntity(de.gurkenlabs.litiengine.entities.IEntity) Material(de.gurkenlabs.litiengine.entities.Material) AttributeModifier(de.gurkenlabs.litiengine.attributes.AttributeModifier) Rotation(de.gurkenlabs.litiengine.entities.Rotation)

Example 12 with IEntity

use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.

the class SpawnpointMapObjectLoader method load.

@Override
public Collection<IEntity> load(IEnvironment environment, IMapObject mapObject) {
    if (MapObjectType.get(mapObject.getType()) != MapObjectType.SPAWNPOINT) {
        throw new IllegalArgumentException("Cannot load a mapobject of the type " + mapObject.getType() + " with a loader of the type " + SpawnpointMapObjectLoader.class);
    }
    final Direction direction = mapObject.getCustomProperty(MapObjectProperty.SPAWN_DIRECTION) != null ? Direction.valueOf(mapObject.getCustomProperty(MapObjectProperty.SPAWN_DIRECTION)) : Direction.DOWN;
    final String spawnType = mapObject.getCustomProperty(MapObjectProperty.SPAWN_TYPE);
    final Spawnpoint spawn = this.createSpawnpoint(mapObject, direction, spawnType);
    loadDefaultProperties(spawn, mapObject);
    Collection<IEntity> entities = super.load(environment, mapObject);
    entities.add(spawn);
    return entities;
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) Direction(de.gurkenlabs.litiengine.entities.Direction) Spawnpoint(de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint)

Example 13 with IEntity

use of de.gurkenlabs.litiengine.entities.IEntity 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)

Example 14 with IEntity

use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.

the class RenderEngine method renderEntity.

@Override
public void renderEntity(final Graphics2D g, final IEntity entity) {
    if (entity == null) {
        return;
    }
    if (entity.getRenderType() == RenderType.NONE || !this.canRender(entity)) {
        return;
    }
    final RenderEvent<IEntity> renderEvent = new RenderEvent<>(g, entity);
    if (!this.entityRenderingConsumer.isEmpty()) {
        for (final Consumer<RenderEvent<IEntity>> consumer : this.entityRenderingConsumer) {
            consumer.accept(renderEvent);
        }
    }
    final IAnimationController animationController = Game.getEntityControllerManager().getAnimationController(entity);
    if (animationController != null) {
        final BufferedImage img = animationController.getCurrentSprite();
        if (img == null) {
            return;
        }
        if (animationController instanceof IEntityAnimationController<?> && ((IEntityAnimationController<?>) animationController).isAutoScaling()) {
            final double ratioX = entity.getWidth() / img.getWidth();
            final double ratioY = entity.getHeight() / img.getHeight();
            renderScaledImage(g, img, Game.getCamera().getViewPortLocation(entity.getLocation()), ratioX, ratioY);
        } else {
            float deltaX = (entity.getWidth() - img.getWidth()) / 2.0f;
            float deltaY = (entity.getHeight() - img.getHeight()) / 2.0f;
            renderImage(g, img, Game.getCamera().getViewPortLocation(entity.getX() + deltaX, entity.getY() + deltaY), animationController.getAffineTransform());
        }
    }
    if (entity instanceof IRenderable) {
        ((IRenderable) entity).render(g);
    }
    if (!this.entityRenderedConsumer.isEmpty()) {
        for (final Consumer<RenderEvent<IEntity>> consumer : this.entityRenderedConsumer) {
            consumer.accept(renderEvent);
        }
    }
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) IAnimationController(de.gurkenlabs.litiengine.graphics.animation.IAnimationController) BufferedImage(java.awt.image.BufferedImage)

Example 15 with IEntity

use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.

the class LightSourceMapObjectLoader method load.

@Override
public Collection<IEntity> load(IEnvironment environment, IMapObject mapObject) {
    if (MapObjectType.get(mapObject.getType()) != MapObjectType.LIGHTSOURCE) {
        throw new IllegalArgumentException("Cannot load a mapobject of the type " + mapObject.getType() + " with a loader of the type " + LightSourceMapObjectLoader.class);
    }
    final int alpha = mapObject.getCustomPropertyInt(MapObjectProperty.LIGHT_ALPHA);
    final int intensity = mapObject.getCustomPropertyInt(MapObjectProperty.LIGHT_INTENSITY, LightSource.DEFAULT_INTENSITY);
    final Color color = mapObject.getCustomPropertyColor(MapObjectProperty.LIGHT_COLOR);
    final boolean active = mapObject.getCustomPropertyBool(MapObjectProperty.LIGHT_ACTIVE, true);
    final String lightShape = mapObject.getCustomProperty(MapObjectProperty.LIGHT_SHAPE);
    Collection<IEntity> entities = super.load(environment, mapObject);
    if (color == null || lightShape == null) {
        return entities;
    }
    String lightType;
    switch(lightShape) {
        case LightSource.ELLIPSE:
            lightType = LightSource.ELLIPSE;
            break;
        case LightSource.RECTANGLE:
            lightType = LightSource.RECTANGLE;
            break;
        default:
            lightType = LightSource.ELLIPSE;
    }
    final LightSource light = this.createLightSource(mapObject, intensity, new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha), lightType, active);
    loadDefaultProperties(light, mapObject);
    entities.add(light);
    return entities;
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) Color(java.awt.Color) LightSource(de.gurkenlabs.litiengine.graphics.LightSource)

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