Search in sources :

Example 1 with ICombatEntity

use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.

the class EnvironmentEventTests method testOnRemoved.

@Test
public void testOnRemoved() {
    ICombatEntity combatEntity = mock(ICombatEntity.class);
    when(combatEntity.getMapId()).thenReturn(123);
    when(combatEntity.getRenderType()).thenReturn(RenderType.NORMAL);
    Consumer<IEntity> removedConsumer = (Consumer<IEntity>) mock(Consumer.class);
    this.testEnvironment.onEntityRemoved(removedConsumer);
    this.testEnvironment.add(combatEntity);
    this.testEnvironment.remove(combatEntity);
    verify(removedConsumer, times(1)).accept(combatEntity);
}
Also used : ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) Consumer(java.util.function.Consumer) IEntity(de.gurkenlabs.litiengine.entities.IEntity) Test(org.junit.jupiter.api.Test)

Example 2 with ICombatEntity

use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.

the class EnvironmentTests method testCombatEntity.

@Test
public void testCombatEntity() {
    ICombatEntity combatEntity = mock(ICombatEntity.class);
    when(combatEntity.getMapId()).thenReturn(123);
    when(combatEntity.getName()).thenReturn("test");
    when(combatEntity.getRenderType()).thenReturn(RenderType.NORMAL);
    this.testEnvironment.add(combatEntity);
    assertNotNull(this.testEnvironment.get(123));
    assertNotNull(this.testEnvironment.getCombatEntity(123));
    assertNotNull(this.testEnvironment.getCombatEntity("test"));
    assertEquals(1, this.testEnvironment.getCombatEntities().size());
    assertEquals(1, this.testEnvironment.getByType(ICombatEntity.class).size());
    assertEquals(1, this.testEnvironment.getEntities().size());
    this.testEnvironment.remove(combatEntity);
    assertNull(this.testEnvironment.get(123));
    assertNull(this.testEnvironment.getCombatEntity(123));
    assertNull(this.testEnvironment.getCombatEntity("test"));
    assertEquals(0, this.testEnvironment.getCombatEntities().size());
    assertEquals(0, this.testEnvironment.getByType(ICombatEntity.class).size());
    assertEquals(0, this.testEnvironment.getEntities().size());
}
Also used : ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ICombatEntity

use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.

the class EnvironmentTests method testFindCombatEntitiesInShape.

@Test
public void testFindCombatEntitiesInShape() {
    ICombatEntity combatEntity = mock(ICombatEntity.class);
    when(combatEntity.getMapId()).thenReturn(123);
    when(combatEntity.getRenderType()).thenReturn(RenderType.NORMAL);
    when(combatEntity.getHitBox()).thenReturn(new Ellipse2D.Double(0, 0, 10, 10));
    ICombatEntity combatEntity2 = mock(ICombatEntity.class);
    when(combatEntity2.getMapId()).thenReturn(456);
    when(combatEntity2.getRenderType()).thenReturn(RenderType.NORMAL);
    when(combatEntity2.getHitBox()).thenReturn(new Ellipse2D.Double(10, 10, 10, 10));
    this.testEnvironment.add(combatEntity);
    this.testEnvironment.add(combatEntity2);
    List<ICombatEntity> found = this.testEnvironment.findCombatEntities(new Rectangle2D.Double(0, 0, 10, 10));
    List<ICombatEntity> found2 = this.testEnvironment.findCombatEntities(new Ellipse2D.Double(0, 0, 10, 10));
    assertTrue(found.contains(combatEntity));
    assertFalse(found.contains(combatEntity2));
    assertTrue(found2.contains(combatEntity));
    assertFalse(found2.contains(combatEntity2));
}
Also used : ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) Rectangle2D(java.awt.geom.Rectangle2D) Ellipse2D(java.awt.geom.Ellipse2D) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ICombatEntity

use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.

the class EnvironmentTests method testEntityByRenderType.

@ParameterizedTest
@EnumSource(value = RenderType.class)
public void testEntityByRenderType(RenderType renderType) {
    ICombatEntity entity = mock(ICombatEntity.class);
    when(entity.getMapId()).thenReturn(123);
    when(entity.getName()).thenReturn("test");
    when(entity.getRenderType()).thenReturn(renderType);
    this.testEnvironment.add(entity);
    assertNotNull(this.testEnvironment.get(123));
    assertNotNull(this.testEnvironment.get("test"));
    assertEquals(1, this.testEnvironment.getEntities(renderType).size());
    this.testEnvironment.remove(entity);
    assertNull(this.testEnvironment.get(123));
    assertNull(this.testEnvironment.get("test"));
    assertEquals(0, this.testEnvironment.getEntities(renderType).size());
}
Also used : ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with ICombatEntity

use of de.gurkenlabs.litiengine.entities.ICombatEntity in project litiengine by gurkenlabs.

the class PhysicsTests method testRectangleCollides.

@Test
public void testRectangleCollides() {
    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(new Rectangle2D.Double(9, 9, 5, 5)));
    assertTrue(engine.collides(new Rectangle2D.Double(9, 9, 5, 5), CollisionType.ENTITY));
    assertTrue(engine.collides(new Rectangle2D.Double(9, 9, 5, 5), CollisionType.ALL));
    assertFalse(engine.collides(new Rectangle2D.Double(9, 9, 5, 5), CollisionType.STATIC));
    assertFalse(engine.collides(new Rectangle2D.Double(9, 9, 5, 5), CollisionType.NONE));
    assertFalse(engine.collides(new Rectangle2D.Double(10.1, 10.1, 5, 5)));
    assertTrue(engine.collidesWithEntites(new Rectangle2D.Double(9, 9, 5, 5)).contains(ent));
}
Also used : ICombatEntity(de.gurkenlabs.litiengine.entities.ICombatEntity) Rectangle2D(java.awt.geom.Rectangle2D) Test(org.junit.jupiter.api.Test)

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