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