use of de.gurkenlabs.litiengine.entities.ICombatEntity 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);
}
}
use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.
the class DebugRenderer method renderEntityDebugInfo.
public static void renderEntityDebugInfo(final Graphics2D g, final IEntity entity) {
if (!Game.getConfiguration().debug().isDebugEnabled()) {
return;
}
if (Game.getConfiguration().debug().renderEntityNames()) {
drawMapId(g, entity);
}
if (Game.getConfiguration().debug().renderHitBoxes() && entity instanceof ICombatEntity) {
g.setColor(Color.RED);
Game.getRenderEngine().renderOutline(g, ((ICombatEntity) entity).getHitBox());
}
if (Game.getConfiguration().debug().renderBoundingBoxes()) {
g.setColor(Color.RED);
Game.getRenderEngine().renderOutline(g, entity.getBoundingBox());
}
if (Game.getConfiguration().debug().renderCollisionBoxes() && entity instanceof ICollisionEntity) {
final ICollisionEntity collisionEntity = (ICollisionEntity) entity;
g.setColor(collisionEntity.hasCollision() ? Color.RED : Color.ORANGE);
Game.getRenderEngine().renderOutline(g, collisionEntity.getCollisionBox());
}
}
use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.
the class LightSource method renderShadows.
/**
* Renders the shadows using simple vector math. The steps are as follows:
*
* <pre>
* for each entity
* if entity is not moving:
* ignore entity
* if entity is too far from mouse:
* ignore entity
*
* determine unit vector from mouse to entity center
* get perpendicular of unit vector
*
* Create Points A + B:
* extrude perpendicular in either direction, by the half-size of the entity
* Create Points C + D:
* extrude A + B away from mouse position
*
* construct polygon with points A, B, C, D
*
* render with RadialGradientPaint to give it a "fade-out" appearance
* </pre>
*
* @param g
* the graphics to use for rendering
* @param center
* the center
*/
private void renderShadows(final Graphics2D g) {
if (!Game.getEnvironment().getCombatEntities().stream().anyMatch(isInRange(this.getCenter(), SHADOW_GRADIENT_SIZE))) {
return;
}
// we'll use a radial gradient
final Paint gradientPaint = new RadialGradientPaint(Game.getCamera().getViewPortDimensionCenter(this), SHADOW_GRADIENT_SIZE, SHADOW_GRADIENT_FRACTIONS, SHADOW_GRADIENT_COLORS);
// old Paint object for resetting it later
final Paint oldPaint = g.getPaint();
g.setPaint(gradientPaint);
// for each entity
for (final ICombatEntity mob : Game.getEnvironment().getCombatEntities()) {
if (mob.isDead() || !isInRange(this.getCenter(), SHADOW_GRADIENT_SIZE).test(mob)) {
continue;
}
final Shape obstructedVision = this.getObstructedVisionArea(mob, Game.getCamera().getViewPortDimensionCenter(this));
// fill the polygon with the gradient paint
g.fill(obstructedVision);
}
// reset to old Paint object
g.setPaint(oldPaint);
}
use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.
the class EnvironmentEventTests method testOnAdded.
@Test
public void testOnAdded() {
ICombatEntity combatEntity = mock(ICombatEntity.class);
when(combatEntity.getMapId()).thenReturn(123);
when(combatEntity.getRenderType()).thenReturn(RenderType.NORMAL);
Consumer<IEntity> addedConsumer = (Consumer<IEntity>) mock(Consumer.class);
this.testEnvironment.onEntityAdded(addedConsumer);
this.testEnvironment.add(combatEntity);
verify(addedConsumer, times(1)).accept(combatEntity);
}
use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.
the class EnvironmentTests method testGetByName.
@Test
public void testGetByName() {
ICombatEntity combatEntity = mock(ICombatEntity.class);
when(combatEntity.getMapId()).thenReturn(1);
when(combatEntity.getName()).thenReturn("test");
when(combatEntity.getRenderType()).thenReturn(RenderType.NORMAL);
ICombatEntity combatEntity2 = mock(ICombatEntity.class);
when(combatEntity2.getRenderType()).thenReturn(RenderType.NORMAL);
this.testEnvironment.add(combatEntity);
this.testEnvironment.add(combatEntity2);
assertNotNull(this.testEnvironment.get("test"));
assertNull(this.testEnvironment.get(""));
assertNull(this.testEnvironment.get(null));
}
Aggregations