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;
}
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;
}
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;
}
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);
}
}
}
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;
}
Aggregations