use of com.b3dgs.lionengine.game.feature.TransformableModel 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());
}
use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.
the class SelectorRefresherTest method prepare.
/**
* Prepare test.
*/
@BeforeEach
public void prepare() {
services.add(new ContextMock());
services.add(new Camera());
services.add(new ViewerMock());
cursor = services.create(Cursor.class);
cursor.setSync(mouse);
final Featurable featurable = new FeaturableModel(services, setup);
featurable.addFeature(new LayerableModel(services, setup));
featurable.addFeature(new TransformableModel(services, setup));
featurable.addFeature(new CollidableModel(services, setup));
refresher = new SelectorRefresher(services, model);
refresher.addListener(listener);
refresher.prepare(featurable);
}
use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.
the class MapTileCollisionModelComplexTest method createObject.
/**
* Create object test.
*
* @return The object test.
*/
private Transformable createObject() {
final Setup setup = new Setup(config);
CollisionCategoryConfig.exports(setup.getRoot(), category);
final FeaturableModel object = new FeaturableModel(services, setup);
final Transformable transformable = object.addFeatureAndGet(new TransformableModel(services, setup));
transformable.setSize(1, 1);
final TileCollidable collidable = object.addFeatureAndGet(new TileCollidableModel(services, setup));
collidable.setEnabled(true);
return transformable;
}
use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.
the class ExtractorModelTest method testStopExtraction.
/**
* Test the stop extraction.
*/
@Test
void testStopExtraction() {
final ObjectExtractor object = new ObjectExtractor(services, setup, true, true);
object.addFeature(new TransformableModel(services, setup));
final Extractor extractor = new ExtractorModel(services, setup);
extractor.prepare(object);
extractor.setCapacity(6);
extractor.setExtractionSpeed(50.0);
extractor.setDropOffSpeed(100.0);
final AtomicReference<String> goTo = new AtomicReference<>();
final AtomicReference<String> startExtract = new AtomicReference<>();
final AtomicReference<String> empty = new AtomicReference<>();
final AtomicReference<String> extracted = new AtomicReference<>();
extractor.addListener(UtilExtractable.createListener(goTo, startExtract, extracted, empty, empty, empty));
assertNull(extractor.getResourceLocation());
assertNull(extractor.getResourceType());
extractor.setResource("wood", 1, 2, 1, 1);
extractor.startExtraction();
assertFalse(extractor.isExtracting());
assertEquals("wood", goTo.get());
extractor.update(1.0);
assertTrue(extractor.isExtracting());
assertEquals("wood", startExtract.get());
assertNotEquals("wood", extracted.get());
extractor.stopExtraction();
extractor.update(1.0);
assertFalse(extractor.isExtracting());
assertNotEquals("wood", extracted.get());
assertNull(goTo.get());
assertNull(startExtract.get());
assertNull(extracted.get());
assertNull(empty.get());
object.getFeature(Identifiable.class).notifyDestroyed();
}
use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.
the class ExtractorModelTest method testListenerAutoAdd.
/**
* Test the auto add listener.
*/
@Test
void testListenerAutoAdd() {
final ObjectExtractorSelf object = new ObjectExtractorSelf(services, setup);
object.addFeature(new TransformableModel(services, setup));
final Extractor extractor = new ExtractorModel(services, setup);
extractor.prepare(object);
extractor.checkListener(new Object());
extractor.checkListener(object);
extractor.setResource("wood", 1, 2, 1, 1);
extractor.startExtraction();
extractor.update(1.0);
assertEquals(2, object.flag.get());
object.getFeature(Identifiable.class).notifyDestroyed();
}
Aggregations