Search in sources :

Example 21 with TransformableModel

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

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

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

the class UtilAttackable method prepare.

/**
 * Create the featurable.
 *
 * @param featurable The featurable to prepare.
 * @param services The services reference.
 * @param setup The setup reference.
 */
public static void prepare(Featurable featurable, Services services, Setup setup) {
    final Animator animator = new AnimatorModel();
    animator.play(new Animation("test", 1, 1, 1.0, false, false));
    featurable.addFeature(new AnimatableModel(services, setup, animator));
    featurable.addFeature(new TransformableModel(services, setup));
}
Also used : Animator(com.b3dgs.lionengine.Animator) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Animation(com.b3dgs.lionengine.Animation) AnimatorModel(com.b3dgs.lionengine.AnimatorModel)

Example 24 with TransformableModel

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

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

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