Search in sources :

Example 21 with Transformable

use of com.b3dgs.lionengine.game.feature.Transformable in project lionengine by b3dgs.

the class AttackerModelTest method testAttackDifferent.

/**
 * Test the attack different target.
 */
@Test
void testAttackDifferent() {
    canAttack.set(true);
    attacker.setAttackChecker(t -> canAttack.get());
    final Transformable target1 = new TransformableModel(services, setup);
    attacker.attack(target1);
    assertEquals(target1, attacker.getTarget());
    assertFalse(attacker.isAttacking());
    attacker.update(1.0);
    attacker.attack(target1);
    assertEquals(target1, attacker.getTarget());
    assertFalse(attacker.isAttacking());
    final Transformable target2 = new TransformableModel(services, setup);
    attacker.stopAttack();
    attacker.attack(target2);
    assertEquals(target2, attacker.getTarget());
    assertFalse(attacker.isAttacking());
    attacker.update(1.0);
    assertEquals(target2, attacker.getTarget());
    assertFalse(attacker.isAttacking());
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) UtilTransformable(com.b3dgs.lionengine.game.feature.UtilTransformable) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Test(org.junit.jupiter.api.Test)

Example 22 with Transformable

use of com.b3dgs.lionengine.game.feature.Transformable in project lionengine by b3dgs.

the class AttackerModelTest method testStopAttack.

/**
 * Test the stop attack.
 */
@Test
void testStopAttack() {
    canAttack.set(true);
    attacker.setAttackChecker(t -> canAttack.get());
    attacker.setAttackDistance(new Range(0, 2));
    final Transformable target = new TransformableModel(services, setup);
    target.teleport(1, 1);
    attacker.attack(target);
    attacker.update(1.0);
    attacker.update(1.0);
    assertTrue(attacker.isAttacking());
    attacker.stopAttack();
    assertTrue(attacker.isAttacking());
    attacker.update(1.0);
    assertFalse(attacker.isAttacking());
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) UtilTransformable(com.b3dgs.lionengine.game.feature.UtilTransformable) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Range(com.b3dgs.lionengine.Range) Test(org.junit.jupiter.api.Test)

Example 23 with Transformable

use of com.b3dgs.lionengine.game.feature.Transformable 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 Transformable

use of com.b3dgs.lionengine.game.feature.Transformable 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 Transformable

use of com.b3dgs.lionengine.game.feature.Transformable 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

Transformable (com.b3dgs.lionengine.game.feature.Transformable)30 Test (org.junit.jupiter.api.Test)17 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)16 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Setup (com.b3dgs.lionengine.game.feature.Setup)8 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)7 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)6 UtilTransformable (com.b3dgs.lionengine.game.feature.UtilTransformable)6 Featurable (com.b3dgs.lionengine.game.feature.Featurable)4 Media (com.b3dgs.lionengine.Media)3 Medias (com.b3dgs.lionengine.Medias)3 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)3 Handler (com.b3dgs.lionengine.game.feature.Handler)3 Services (com.b3dgs.lionengine.game.feature.Services)3 Animation (com.b3dgs.lionengine.Animation)2 Range (com.b3dgs.lionengine.Range)2 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)2 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)2 Force (com.b3dgs.lionengine.game.Force)2