use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.
the class PhysicsTests method testPointCollides.
@Test
public void testPointCollides() {
ICombatEntity ent = mock(ICombatEntity.class);
when(ent.getCollisionBox()).thenReturn(new Rectangle2D.Double(0, 0, 10, 10));
when(ent.hasCollision()).thenReturn(true);
IPhysicsEngine engine = new PhysicsEngine();
engine.add(ent);
engine.update();
assertTrue(engine.collides(5, 5));
assertTrue(engine.collides(5, 5, CollisionType.ALL));
assertTrue(engine.collides(5, 5, CollisionType.ENTITY));
assertFalse(engine.collides(5, 5, CollisionType.STATIC));
assertFalse(engine.collides(5, 5, CollisionType.NONE));
engine.remove(ent);
engine.update();
assertFalse(engine.collides(5, 5));
}
use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.
the class PhysicsTests method testRaycastCollides.
@Test
public void testRaycastCollides() {
ICombatEntity ent = mock(ICombatEntity.class);
when(ent.getCollisionBox()).thenReturn(new Rectangle2D.Double(0, 0, 10, 10));
when(ent.hasCollision()).thenReturn(true);
IPhysicsEngine engine = new PhysicsEngine();
engine.add(ent);
engine.add(new Rectangle2D.Double(5, 5, 10, 10));
engine.update();
assertNotNull(engine.collides(new Line2D.Double(0, 0, 5, 5)));
assertNotNull(engine.collides(new Line2D.Double(10, 10, 5, 5)));
assertNull(engine.collides(new Line2D.Double(15.1, 15.0, 15, 15)));
}
use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.
the class Environment method remove.
@Override
public void remove(final IEntity entity) {
if (entity == null) {
return;
}
if (this.entities.get(entity.getRenderType()) != null) {
this.entities.get(entity.getRenderType()).entrySet().removeIf(e -> e.getValue().getMapId() == entity.getMapId());
}
for (String tag : entity.getTags()) {
if (this.entitiesByTag.containsKey(tag)) {
this.entitiesByTag.get(tag).remove(entity);
if (this.entitiesByTag.get(tag).isEmpty()) {
this.entitiesByTag.remove(tag);
}
}
}
if (entity instanceof Emitter) {
Emitter emitter = (Emitter) entity;
this.groundRenderable.remove(emitter.getGroundRenderable());
this.overlayRenderable.remove(emitter.getOverlayRenderable());
this.emitters.remove(emitter);
}
if (entity instanceof MapArea) {
this.mapAreas.remove(entity);
}
if (entity instanceof Prop) {
this.props.remove(entity);
}
if (entity instanceof Creature) {
this.creatures.remove(entity);
}
if (entity instanceof CollisionBox) {
this.colliders.remove(entity);
this.staticShadows.removeIf(x -> x.getOrigin() != null && x.getOrigin().equals(entity));
}
if (entity instanceof LightSource) {
this.lightSources.remove(entity);
this.updateColorLayers(entity);
}
if (entity instanceof Trigger) {
this.triggers.remove(entity);
}
if (entity instanceof Spawnpoint) {
this.spawnPoints.remove(entity);
}
if (entity instanceof StaticShadow) {
this.staticShadows.remove(entity);
this.updateColorLayers(entity);
}
if (entity instanceof IMobileEntity) {
this.mobileEntities.values().remove(entity);
}
if (entity instanceof ICombatEntity) {
this.combatEntities.values().remove(entity);
}
this.unload(entity);
for (Consumer<IEntity> cons : this.entityRemovedConsumers) {
cons.accept(entity);
}
}
use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.
the class Effect method lookForAffectedEntities.
protected List<ICombatEntity> lookForAffectedEntities(final Shape impactArea) {
List<ICombatEntity> affectedEntities = new ArrayList<>();
for (final EffectTarget target : this.effectTargets) {
switch(target) {
case EXECUTINGENTITY:
affectedEntities.add(this.getAbility().getExecutor());
return affectedEntities;
case ENEMY:
affectedEntities.addAll(this.getEntitiesInImpactArea(impactArea));
affectedEntities = affectedEntities.stream().filter(this.canAttackEntity()).collect(Collectors.toList());
break;
case FRIENDLY:
affectedEntities.addAll(this.getEntitiesInImpactArea(impactArea));
affectedEntities = affectedEntities.stream().filter(this.isAliveFriendlyEntity()).collect(Collectors.toList());
break;
case FRIENDLYDEAD:
affectedEntities.addAll(this.getEntitiesInImpactArea(impactArea));
affectedEntities = affectedEntities.stream().filter(this.isDeadFriendlyEntity()).collect(Collectors.toList());
break;
default:
break;
}
}
affectedEntities.removeAll(Collections.singleton(null));
affectedEntities.sort(this.targetPriorityComparator);
if (!this.getAbility().isMultiTarget() && !affectedEntities.isEmpty()) {
final ICombatEntity target;
if (this.getAbility().getExecutor().getTarget() != null) {
target = this.getAbility().getExecutor().getTarget();
} else {
target = affectedEntities.get(0);
}
affectedEntities = new ArrayList<>();
affectedEntities.add(target);
}
return affectedEntities;
}
use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.
the class Effect method apply.
@Override
public void apply(final Shape impactArea) {
final List<ICombatEntity> affected = this.lookForAffectedEntities(impactArea);
for (final ICombatEntity affectedEntity : affected) {
this.apply(affectedEntity);
}
this.appliances.add(new EffectApplication(affected, impactArea));
// if it is the first appliance -> register for update
if (this.appliances.size() == 1) {
Game.getLoop().attach(this);
}
}
Aggregations