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);
}
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());
}
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));
}
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());
}
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));
}
Aggregations