use of com.b3dgs.lionengine.game.feature.FeaturableModel in project lionengine by b3dgs.
the class CollidableModelTest method createFeaturable.
/**
* Create a featurable test.
*
* @param config The configuration reference.
* @param services The services reference.
* @return The featurable test.
*/
public static FeaturableModel createFeaturable(Media config, Services services) {
final Setup setup = new Setup(config);
final FeaturableModel featurable = new FeaturableModel(services, setup);
final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
transformable.setLocation(1.0, 2.0);
transformable.setSize(2, 2);
featurable.addFeature(new CollidableModel(services, setup));
return featurable;
}
use of com.b3dgs.lionengine.game.feature.FeaturableModel in project lionengine by b3dgs.
the class CollidableFramedModelTest method createFeaturable.
/**
* Create a featurable test.
*
* @param config The configuration reference.
* @param services The services reference.
* @return The featurable test.
*/
public static FeaturableModel createFeaturable(Media config, Services services) {
final Setup setup = new Setup(config);
final FeaturableModel featurable = new FeaturableModel(services, setup);
final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
transformable.setLocation(1.0, 2.0);
featurable.addFeature(new AnimatableModel(services, setup));
featurable.addFeatureAndGet(new CollidableModel(services, setup));
featurable.addFeature(new CollidableFramedModel(services, setup));
return featurable;
}
use of com.b3dgs.lionengine.game.feature.FeaturableModel in project lionengine by b3dgs.
the class FogOfWarTest method testFogOfWar.
/**
* Test the fog of war.
*/
@Test
void testFogOfWar() {
final Setup setup = new Setup(config);
final FeaturableModel object = new FeaturableModel(services, setup);
final Transformable transformable = object.addFeatureAndGet(new TransformableModel(services, setup));
final FovableModel fovable = object.addFeatureAndGet(new FovableModel(services, setup));
fovable.prepare(object);
fovable.setFov(1);
Medias.setLoadFromJar(MapTileFog.class);
fog.setEnabled(true, true);
fog.create(Medias.create("fog.xml"));
Medias.setLoadFromJar(null);
final AtomicInteger rtx = new AtomicInteger();
final AtomicInteger rty = new AtomicInteger();
final AtomicInteger count = new AtomicInteger();
final RevealedListener listener = (tx, ty) -> {
rtx.set(tx);
rty.set(ty);
count.incrementAndGet();
};
fog.addListener(listener);
assertFalse(fog.isFogged(2, 3));
assertFalse(fog.isFogged(3, 3));
assertFalse(fog.isFogged(4, 3));
assertFalse(fog.isVisible(map.getTile(2, 3)));
assertFalse(fog.isVisible(map.getTile(3, 3)));
assertFalse(fog.isVisible(map.getTile(4, 3)));
assertFalse(fog.isVisited(2, 3));
assertFalse(fog.isVisited(3, 3));
assertFalse(fog.isVisited(4, 3));
assertFalse(fog.isVisited(Geom.createArea(3, 3, 1, 1)));
transformable.teleport(3, 3);
fog.update(fovable);
assertTrue(fog.isFogged(2, 3));
assertFalse(fog.isFogged(3, 3));
assertTrue(fog.isFogged(4, 3));
assertFalse(fog.isVisible(map.getTile(2, 3)));
assertTrue(fog.isVisible(map.getTile(3, 3)));
assertFalse(fog.isVisible(map.getTile(4, 3)));
assertFalse(fog.isVisited(2, 3));
assertTrue(fog.isVisited(3, 3));
assertFalse(fog.isVisited(4, 3));
assertTrue(fog.isVisited(Geom.createArea(3, 3, 1, 1)));
assertEquals(1, count.get());
assertEquals(3, rtx.get());
assertEquals(3, rty.get());
transformable.setLocation(6, 6);
fog.removeListener(listener);
count.set(0);
fog.update(fovable);
assertFalse(fog.isFogged(2, 3));
assertTrue(fog.isFogged(3, 3));
assertTrue(fog.isFogged(4, 3));
assertFalse(fog.isVisible(map.getTile(2, 3)));
assertFalse(fog.isVisible(map.getTile(3, 3)));
assertFalse(fog.isVisible(map.getTile(4, 3)));
assertFalse(fog.isVisited(2, 3));
assertTrue(fog.isVisited(3, 3));
assertFalse(fog.isVisited(4, 3));
assertTrue(fog.isVisited(Geom.createArea(3, 3, 1, 1)));
assertEquals(0, count.get());
fog.setEnabled(false, false);
assertFalse(fog.isFogged(2, 3));
assertFalse(fog.isFogged(3, 3));
assertFalse(fog.isFogged(4, 3));
assertTrue(fog.isVisible(map.getTile(2, 3)));
assertTrue(fog.isVisible(map.getTile(3, 3)));
assertTrue(fog.isVisible(map.getTile(4, 3)));
assertTrue(fog.isVisited(2, 3));
assertTrue(fog.isVisited(3, 3));
assertTrue(fog.isVisited(4, 3));
assertTrue(fog.isVisited(Geom.createArea(3, 3, 1, 1)));
}
use of com.b3dgs.lionengine.game.feature.FeaturableModel in project lionengine by b3dgs.
the class FovableModelTest method testFovable.
/**
* Test the fovable model.
*/
@Test
void testFovable() {
final MapTile map = UtilMap.createMap(7);
services.add(map);
final Setup setup = new Setup(config);
final Fovable fovable = new FovableModel(services, setup);
final Featurable featurable = new FeaturableModel(services, setup);
final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
transformable.teleport(1, 2);
transformable.setSize(3, 4);
fovable.prepare(featurable);
fovable.setFov(5);
assertEquals(1, fovable.getInTileX());
assertEquals(2, fovable.getInTileY());
assertEquals(3, fovable.getInTileWidth());
assertEquals(4, fovable.getInTileHeight());
assertEquals(5, fovable.getInTileFov());
assertTrue(fovable.canUpdate());
fovable.setCanUpdate(() -> false);
assertFalse(fovable.canUpdate());
}
use of com.b3dgs.lionengine.game.feature.FeaturableModel in project lionengine by b3dgs.
the class MapTileFogTest method testFog.
/**
* Test the fog.
*/
@Test
void testFog() {
final MapTile map = UtilMap.createMap(5);
services.add(map);
final FovableModel fovable = new FovableModel(services, setup);
final FeaturableModel object = new FeaturableModel(services, setup);
final Transformable transformable = object.addFeatureAndGet(new TransformableModel(services, setup));
transformable.teleport(3, 3);
fovable.prepare(object);
fovable.setFov(1);
final MapTileFog fog = new MapTileFog();
Medias.setLoadFromJar(MapTileFog.class);
fog.create(map.getFeature(MapTileSurface.class), Medias.create("fog.xml"), null);
Medias.setLoadFromJar(null);
final AtomicInteger rtx = new AtomicInteger();
final AtomicInteger rty = new AtomicInteger();
final AtomicInteger count = new AtomicInteger();
final RevealedListener listener = (tx, ty) -> {
rtx.set(tx);
rty.set(ty);
count.incrementAndGet();
};
fog.addListener(listener);
assertEquals(16, fog.getTile(2, 3).getNumber());
assertEquals(16, fog.getTile(3, 3).getNumber());
assertEquals(16, fog.getTile(4, 3).getNumber());
fog.updateFov(fovable);
assertEquals(10, fog.getTile(2, 2).getNumber());
assertEquals(1, fog.getTile(3, 2).getNumber());
assertEquals(11, fog.getTile(4, 2).getNumber());
assertEquals(2, fog.getTile(2, 3).getNumber());
assertEquals(17, fog.getTile(3, 3).getNumber());
assertEquals(3, fog.getTile(4, 3).getNumber());
assertEquals(8, fog.getTile(2, 4).getNumber());
assertEquals(0, fog.getTile(3, 4).getNumber());
assertEquals(9, fog.getTile(4, 4).getNumber());
assertEquals(1, count.get());
assertEquals(3, rtx.get());
assertEquals(3, rty.get());
fog.reset(fovable);
fog.removeListener(listener);
count.set(0);
assertEquals(16, fog.getTile(2, 3).getNumber());
assertEquals(16, fog.getTile(3, 3).getNumber());
assertEquals(16, fog.getTile(4, 3).getNumber());
fog.updateFov(fovable);
assertEquals(0, count.get());
}
Aggregations