use of de.gurkenlabs.litiengine.entities.LightSource in project litiengine by gurkenlabs.
the class EnvironmentTests method testLightSource.
@Test
void testLightSource() {
LightSource testLight = new LightSource(100, new Color(255, 255, 255, 100), LightSource.Type.ELLIPSE, true);
testLight.setMapId(999);
testLight.setName("test");
this.testEnvironment.add(testLight);
assertNotNull(this.testEnvironment.getLightSource(999));
assertNotNull(this.testEnvironment.getLightSource("test"));
assertEquals(1, this.testEnvironment.getEntities(LightSource.class).size());
assertEquals(1, this.testEnvironment.getEntities().size());
this.testEnvironment.remove(testLight);
assertNull(this.testEnvironment.getLightSource(999));
assertNull(this.testEnvironment.getLightSource("test"));
assertEquals(0, this.testEnvironment.getEntities(LightSource.class).size());
assertEquals(0, this.testEnvironment.getEntities().size());
}
use of de.gurkenlabs.litiengine.entities.LightSource in project litiengine by gurkenlabs.
the class AmbientLight method renderSection.
/**
* @see <a href="https://docs.oracle.com/javase/tutorial/2d/advanced/compositing.html">Compositing Graphics</a>
*/
@Override
protected void renderSection(Graphics2D g, Rectangle2D section) {
this.renderAmbient(g, section);
// carve out the lights that will be added
g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OUT, 1));
for (final LightSource light : this.getEnvironment().getLightSources()) {
if (!light.getBoundingBox().intersects(section) || !light.isActive()) {
continue;
}
this.renderLightSource(g, light, section);
}
// render the actual lights, depending on their intensity
for (final LightSource light : this.getEnvironment().getLightSources()) {
if (!light.getBoundingBox().intersects(section) || !light.isActive() || light.getIntensity() <= 0) {
continue;
}
final float intensity = MathUtilities.clamp((float) light.getIntensity() / 255, 0, 1);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, intensity));
this.renderLightSource(g, light, section);
}
}
use of de.gurkenlabs.litiengine.entities.LightSource in project litiengine by gurkenlabs.
the class LightSourceMapObjectLoader method load.
@Override
public Collection<IEntity> load(Environment environment, IMapObject mapObject) {
Collection<IEntity> entities = new ArrayList<>();
if (!this.isMatchingType(mapObject)) {
return entities;
}
final int intensity = mapObject.getIntValue(MapObjectProperty.LIGHT_INTENSITY, LightSource.DEFAULT_INTENSITY);
final Color color = mapObject.getColorValue(MapObjectProperty.LIGHT_COLOR);
final boolean active = mapObject.getBoolValue(MapObjectProperty.LIGHT_ACTIVE, true);
final LightSource.Type lightType = mapObject.getEnumValue(MapObjectProperty.LIGHT_SHAPE, LightSource.Type.class);
final double focusOffsetX = mapObject.getDoubleValue(MapObjectProperty.LIGHT_FOCUSOFFSETX);
final double focusOffsetY = mapObject.getDoubleValue(MapObjectProperty.LIGHT_FOCUSOFFSETY);
if (color == null) {
return entities;
}
final LightSource light = this.createLightSource(mapObject, intensity, color, lightType, active);
loadDefaultProperties(light, mapObject);
light.setFocusOffsetX(focusOffsetX);
light.setFocusOffsetY(focusOffsetY);
entities.add(light);
return entities;
}
use of de.gurkenlabs.litiengine.entities.LightSource in project litiengine by gurkenlabs.
the class Environment method unload.
/**
* Unload the specified entity by performing the following steps:
* <ol>
* <li>remove entities from physics engine</li>
* <li>unregister units from update</li>
* <li>unregister ai controller from update</li>
* <li>unregister animation controller from update</li>
* <li>unregister movement controller from update</li>
* </ol>
*
* @param entity
*/
private void unload(final IEntity entity) {
// 1. remove from physics engine
if (entity instanceof ICollisionEntity) {
Game.physics().remove((ICollisionEntity) entity);
}
// 2. unregister from update
if (entity instanceof IUpdateable) {
Game.loop().detach((IUpdateable) entity);
}
if (entity instanceof IMobileEntity) {
this.removeGravity((IMobileEntity) entity);
}
// 3. detach all controllers
entity.detachControllers();
if (entity instanceof Emitter) {
Emitter em = (Emitter) entity;
em.deactivate();
}
if (this.loaded && (entity instanceof LightSource || entity instanceof StaticShadow)) {
this.updateLighting(entity);
}
entity.removed(this);
}
use of de.gurkenlabs.litiengine.entities.LightSource in project litiengine by gurkenlabs.
the class EnvironmentTests method testAddRenderable.
@Test
void testAddRenderable() {
LightSource testLightSource = mock(LightSource.class);
this.testEnvironment.add(testLightSource, RenderType.NORMAL);
Collection<IRenderable> testRenderables = this.testEnvironment.getRenderables(RenderType.NORMAL);
assertEquals(1, testRenderables.size());
assertTrue(testRenderables.contains(testLightSource));
}
Aggregations