Search in sources :

Example 21 with FeaturableModel

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;
}
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 22 with FeaturableModel

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;
}
Also used : CollidableModel(com.b3dgs.lionengine.game.feature.collidable.CollidableModel) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) 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 23 with FeaturableModel

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)));
}
Also used : Medias(com.b3dgs.lionengine.Medias) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) BeforeEach(org.junit.jupiter.api.BeforeEach) UtilAssert.assertFalse(com.b3dgs.lionengine.UtilAssert.assertFalse) Graphic(com.b3dgs.lionengine.graphic.Graphic) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) UtilMap(com.b3dgs.lionengine.game.feature.tile.map.UtilMap) Graphics(com.b3dgs.lionengine.graphic.Graphics) 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) Geom(com.b3dgs.lionengine.geom.Geom) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) Test(org.junit.jupiter.api.Test)

Example 24 with FeaturableModel

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());
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilTransformable(com.b3dgs.lionengine.game.feature.UtilTransformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 25 with FeaturableModel

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

Aggregations

FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)33 Test (org.junit.jupiter.api.Test)20 Featurable (com.b3dgs.lionengine.game.feature.Featurable)18 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)18 Transformable (com.b3dgs.lionengine.game.feature.Transformable)16 Setup (com.b3dgs.lionengine.game.feature.Setup)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)7 Media (com.b3dgs.lionengine.Media)6 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)6 Services (com.b3dgs.lionengine.game.feature.Services)5 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)5 Medias (com.b3dgs.lionengine.Medias)4 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)4 Animation (com.b3dgs.lionengine.Animation)3 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)3 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)3 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)3 UtilTransformable (com.b3dgs.lionengine.game.feature.UtilTransformable)3 MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)3