Search in sources :

Example 11 with Transformable

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

the class TileCollidableModelTest method testFromTop.

/**
 * Test the collidable from top.
 */
@Test
void testFromTop() {
    final Transformable transformable = createObject(new FeaturableModel(services, setup));
    final AtomicReference<Tile> collided = new AtomicReference<>();
    final TileCollidableListener listener = createListener(collided);
    collidable.addListener(listener);
    transformable.teleport(0.0, 3.0);
    transformable.moveLocation(1.0, 0.0, -2.0);
    collidable.update(1.0);
    assertEquals(map.getTile(0, 2), collided.get());
}
Also used : Transformable(com.b3dgs.lionengine.game.feature.Transformable) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 12 with Transformable

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

the class TileCollidableModelTest method createObject.

/**
 * Create object test.
 *
 * @param featurable Featurable instance.
 * @return The object test.
 */
private Transformable createObject(Featurable featurable) {
    final Setup setup = new Setup(config);
    CollisionCategoryConfig.exports(setup.getRoot(), categoryY);
    CollisionCategoryConfig.exports(setup.getRoot(), categoryX);
    final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
    transformable.setSize(2, 2);
    collidable = featurable.addFeatureAndGet(new TileCollidableModel(services, setup));
    collidable.setEnabled(true);
    assertArrayEquals(Arrays.asList(categoryY, categoryX).toArray(), collidable.getCategories().toArray());
    return transformable;
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup)

Example 13 with Transformable

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

the class TileCollidableModelTest method testDisabled.

/**
 * Test the collidable disabled.
 */
@Test
void testDisabled() {
    final Transformable transformable = createObject(new FeaturableModel(services, setup));
    final AtomicReference<Tile> collided = new AtomicReference<>();
    final TileCollidableListener listener = createListener(collided);
    collidable.addListener(listener);
    collidable.setEnabled(false);
    transformable.teleport(0, 2);
    transformable.moveLocation(1.0, 0.0, -1.0);
    collidable.update(1.0);
    assertNull(collided.get());
}
Also used : Transformable(com.b3dgs.lionengine.game.feature.Transformable) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 14 with Transformable

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

the class TileCollidableModelTest method testSelfListener.

/**
 * Test the collidable self listener.
 */
@Test
void testSelfListener() {
    final ObjectSelf self = new ObjectSelf(services, setup);
    final Transformable transformable = createObject(self);
    final AtomicReference<Tile> collided = new AtomicReference<>();
    final TileCollidableListener listener = createListener(collided);
    collidable.addListener(listener);
    transformable.teleport(0.0, 2.0);
    transformable.moveLocation(1.0, 0.0, -1.0);
    collidable.removeListener(listener);
    collidable.update(1.0);
    assertNull(collided.get());
    assertTrue(self.called.get());
}
Also used : Transformable(com.b3dgs.lionengine.game.feature.Transformable) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 15 with Transformable

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

the class TileCollidableModelTest method testRemoveListener.

/**
 * Test the collidable with remove listener.
 */
@Test
void testRemoveListener() {
    final Transformable transformable = createObject(new FeaturableModel(services, setup));
    final AtomicReference<Tile> collided = new AtomicReference<>();
    final TileCollidableListener listener = createListener(collided);
    collidable.checkListener(transformable);
    collidable.checkListener(listener);
    transformable.teleport(0.0, 2.0);
    transformable.moveLocation(1.0, 0.0, -1.0);
    collidable.update(1.0);
    assertNotNull(collided.get());
    collided.set(null);
    collidable.removeListener(listener);
    collidable.update(1.0);
    assertNull(collided.get());
}
Also used : Transformable(com.b3dgs.lionengine.game.feature.Transformable) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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