Search in sources :

Example 1 with AttributeModifier

use of de.gurkenlabs.litiengine.attributes.AttributeModifier 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)

Aggregations

AttributeModifier (de.gurkenlabs.litiengine.attributes.AttributeModifier)1 IEntity (de.gurkenlabs.litiengine.entities.IEntity)1 Material (de.gurkenlabs.litiengine.entities.Material)1 Prop (de.gurkenlabs.litiengine.entities.Prop)1 Rotation (de.gurkenlabs.litiengine.entities.Rotation)1