Search in sources :

Example 11 with ICombatEntity

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));
}
Also used : ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) Rectangle2D(java.awt.geom.Rectangle2D) Test(org.junit.jupiter.api.Test)

Example 12 with ICombatEntity

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)));
}
Also used : ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) Rectangle2D(java.awt.geom.Rectangle2D) Test(org.junit.jupiter.api.Test)

Example 13 with ICombatEntity

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);
    }
}
Also used : Emitter(de.gurkenlabs.litiengine.graphics.particles.Emitter) Creature(de.gurkenlabs.litiengine.entities.Creature) ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) Prop(de.gurkenlabs.litiengine.entities.Prop) IEntity(de.gurkenlabs.litiengine.entities.IEntity) MapArea(de.gurkenlabs.litiengine.environment.tilemap.MapArea) Trigger(de.gurkenlabs.litiengine.entities.Trigger) StaticShadow(de.gurkenlabs.litiengine.graphics.StaticShadow) IMobileEntity(de.gurkenlabs.litiengine.entities.IMobileEntity) LightSource(de.gurkenlabs.litiengine.graphics.LightSource) Spawnpoint(de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint) CollisionBox(de.gurkenlabs.litiengine.entities.CollisionBox)

Example 14 with ICombatEntity

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;
}
Also used : ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 15 with ICombatEntity

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);
    }
}
Also used : ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity)

Aggregations

ICombatEntity (de.gurkenlabs.litiengine.entities.ICombatEntity)15 Test (org.junit.jupiter.api.Test)8 IEntity (de.gurkenlabs.litiengine.entities.IEntity)4 Rectangle2D (java.awt.geom.Rectangle2D)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)2 Creature (de.gurkenlabs.litiengine.entities.Creature)2 IMobileEntity (de.gurkenlabs.litiengine.entities.IMobileEntity)2 Prop (de.gurkenlabs.litiengine.entities.Prop)2 Trigger (de.gurkenlabs.litiengine.entities.Trigger)2 MapArea (de.gurkenlabs.litiengine.environment.tilemap.MapArea)2 Spawnpoint (de.gurkenlabs.litiengine.environment.tilemap.Spawnpoint)2 LightSource (de.gurkenlabs.litiengine.graphics.LightSource)2 StaticShadow (de.gurkenlabs.litiengine.graphics.StaticShadow)2 Emitter (de.gurkenlabs.litiengine.graphics.particles.Emitter)2 Consumer (java.util.function.Consumer)2 ICollisionEntity (de.gurkenlabs.litiengine.entities.ICollisionEntity)1 Paint (java.awt.Paint)1 RadialGradientPaint (java.awt.RadialGradientPaint)1 Shape (java.awt.Shape)1