Search in sources :

Example 26 with TransformableModel

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());
}
Also used : Medias(com.b3dgs.lionengine.Medias) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilTransformable(com.b3dgs.lionengine.game.feature.UtilTransformable) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) UtilMap(com.b3dgs.lionengine.game.feature.tile.map.UtilMap) Services(com.b3dgs.lionengine.game.feature.Services) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) MapTileSurface(com.b3dgs.lionengine.game.feature.tile.map.MapTileSurface) UtilMapTransition(com.b3dgs.lionengine.game.feature.tile.map.transition.UtilMapTransition) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapTileSurface(com.b3dgs.lionengine.game.feature.tile.map.MapTileSurface) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilTransformable(com.b3dgs.lionengine.game.feature.UtilTransformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Example 27 with TransformableModel

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);
}
Also used : CollidableModel(com.b3dgs.lionengine.game.feature.collidable.CollidableModel) ViewerMock(com.b3dgs.lionengine.ViewerMock) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Camera(com.b3dgs.lionengine.game.feature.Camera) ContextMock(com.b3dgs.lionengine.ContextMock) Cursor(com.b3dgs.lionengine.game.Cursor) Featurable(com.b3dgs.lionengine.game.feature.Featurable) SelectorRefresher(com.b3dgs.lionengine.game.feature.collidable.selector.SelectorRefresher) LayerableModel(com.b3dgs.lionengine.game.feature.LayerableModel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 28 with TransformableModel

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;
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup)

Example 29 with TransformableModel

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();
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.jupiter.api.Test)

Example 30 with TransformableModel

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();
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.jupiter.api.Test)

Aggregations

TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)37 Test (org.junit.jupiter.api.Test)20 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)19 Transformable (com.b3dgs.lionengine.game.feature.Transformable)17 Setup (com.b3dgs.lionengine.game.feature.Setup)12 Featurable (com.b3dgs.lionengine.game.feature.Featurable)11 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)10 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)9 Media (com.b3dgs.lionengine.Media)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)5 Services (com.b3dgs.lionengine.game.feature.Services)5 UtilTransformable (com.b3dgs.lionengine.game.feature.UtilTransformable)5 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)5 Medias (com.b3dgs.lionengine.Medias)4 Handler (com.b3dgs.lionengine.game.feature.Handler)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Animation (com.b3dgs.lionengine.Animation)3 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)3 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)3