Search in sources :

Example 21 with Tile

use of com.b3dgs.lionengine.game.feature.tile.Tile 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 22 with Tile

use of com.b3dgs.lionengine.game.feature.tile.Tile 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 23 with Tile

use of com.b3dgs.lionengine.game.feature.tile.Tile 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 24 with Tile

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

Example 25 with Tile

use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.

the class TileCollidableModelTest method testFromRight.

/**
 * Test the collidable from right.
 */
@Test
void testFromRight() {
    final Transformable transformable = createObject(new FeaturableModel(services, setup));
    final AtomicReference<Tile> collided = new AtomicReference<>();
    final TileCollidableListener listener = createListener(collided);
    collidable.addListener(listener);
    transformable.teleport(3.0, 0.0);
    transformable.moveLocation(1.0, -2.0, 0.0);
    collidable.update(1.0);
    assertEquals(map.getTile(2, 0), 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

Tile (com.b3dgs.lionengine.game.feature.tile.Tile)59 MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)26 Test (org.junit.jupiter.api.Test)13 TileGame (com.b3dgs.lionengine.game.feature.tile.TileGame)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 Transformable (com.b3dgs.lionengine.game.feature.Transformable)7 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)6 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 MapTileGroup (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 LionEngineException (com.b3dgs.lionengine.LionEngineException)2 Media (com.b3dgs.lionengine.Media)2 Force (com.b3dgs.lionengine.game.Force)2 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)2 MapTileTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition)2 SpriteTiled (com.b3dgs.lionengine.graphic.SpriteTiled)2 GroupTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.GroupTransition)1