use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.
the class MapObjectLoaderTests method testColliderMapObjectLoader.
@Test
public void testColliderMapObjectLoader() {
CollisionBoxMapObjectLoader loader = new CollisionBoxMapObjectLoader();
IEnvironment environment = mock(IEnvironment.class);
IMapObject mapObject = mock(IMapObject.class);
when(mapObject.getType()).thenReturn(MapObjectType.COLLISIONBOX.name());
when(mapObject.getId()).thenReturn(111);
when(mapObject.getName()).thenReturn("testCollider");
when(mapObject.getLocation()).thenReturn(new Point(100, 100));
when(mapObject.getDimension()).thenReturn(new Dimension(200, 200));
when(mapObject.getWidth()).thenReturn(200);
when(mapObject.getHeight()).thenReturn(200);
Collection<IEntity> entities = loader.load(environment, mapObject);
Optional<IEntity> opt = entities.stream().findFirst();
assertTrue(opt.isPresent());
IEntity entity = entities.stream().findFirst().get();
assertNotNull(entity);
assertEquals(entity.getMapId(), 111);
assertEquals(entity.getName(), "testCollider");
assertEquals(entity.getLocation().getX(), 100, 0.0001);
assertEquals(entity.getLocation().getY(), 100, 0.0001);
CollisionBox collider = (CollisionBox) entity;
assertEquals(collider.getCollisionBoxWidth(), 200.0, 0.0001);
assertEquals(collider.getCollisionBoxHeight(), 200.0, 0.0001);
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.
the class PropertyPanel method updateEnvironment.
protected void updateEnvironment() {
if (getDataSource() instanceof IMapObject) {
IMapObject obj = (IMapObject) getDataSource();
Game.getEnvironment().reloadFromMap(obj.getId());
if (MapObjectType.get(obj.getType()) == MapObjectType.LIGHTSOURCE) {
Game.getEnvironment().getAmbientLight().updateSection(getDataSource().getBoundingBox());
}
}
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.
the class Environment method loadFromMap.
@Override
public void loadFromMap(final int mapId) {
for (final IMapObjectLayer layer : this.getMap().getMapObjectLayers()) {
Optional<IMapObject> opt = layer.getMapObjects().stream().filter(mapObject -> mapObject.getType() != null && !mapObject.getType().isEmpty() && mapObject.getId() == mapId).findFirst();
if (opt.isPresent()) {
IMapObject mapObject = opt.get();
this.addMapObject(mapObject);
break;
}
}
}
Aggregations