use of com.b3dgs.lionengine.game.feature.Transformable in project lionengine by b3dgs.
the class AttackerModelTest method testCustomDistandceComputer.
/**
* Test the custom distance computer.
*/
@Test
void testCustomDistandceComputer() {
assertThrows(() -> attacker.setAttackDistanceComputer(null), "Unexpected null argument !");
canAttack.set(true);
attacker.setAttackChecker(t -> canAttack.get());
final Transformable target = new TransformableModel(services, setup);
target.teleport(1, 1);
attacker.setAttackDistanceComputer((s, t) -> 5);
attacker.attack(target);
attacker.update(1.0);
assertFalse(attacker.isAttacking());
attacker.setAttackDistanceComputer((s, t) -> 1);
attacker.update(1.0);
attacker.update(1.0);
assertTrue(attacker.isAttacking());
}
use of com.b3dgs.lionengine.game.feature.Transformable in project lionengine by b3dgs.
the class LauncherModelTest method testLauncher.
/**
* Test the launcher.
*
* @throws InterruptedException If error.
*/
@Test
void testLauncher() throws InterruptedException {
final AtomicBoolean fired = new AtomicBoolean();
final AtomicReference<Launchable> firedLaunchable = new AtomicReference<>();
launcher.addListener(UtilLaunchable.createListener(fired));
launcher.addListener(UtilLaunchable.createListener(firedLaunchable));
assertTimeout(1000L, () -> {
while (!launcher.fire()) {
launcher.update(1.0);
continue;
}
});
assertTrue(fired.get());
assertNotNull(firedLaunchable.get());
firedLaunchable.set(null);
final Handler handler = services.get(Handler.class);
handler.update(1.0);
assertEquals(1, handler.size());
final Transformable transformable = new TransformableModel(services, setup);
assertTimeout(1000L, () -> {
while (!launcher.fire(transformable)) {
launcher.update(1.0);
continue;
}
});
assertNotNull(firedLaunchable.get());
firedLaunchable.set(null);
handler.update(1.0);
assertEquals(2, handler.size());
final Localizable localizable = UtilLaunchable.createLocalizable();
assertTimeout(1000L, () -> {
while (!launcher.fire(localizable)) {
launcher.update(1.0);
continue;
}
});
assertNotNull(firedLaunchable.get());
handler.update(1.0);
assertEquals(3, handler.size());
handler.removeAll();
handler.update(1.0);
assertEquals(0, handler.size());
}
use of com.b3dgs.lionengine.game.feature.Transformable in project lionengine by b3dgs.
the class SceneRasterable method add.
private void add(SetupSurfaceRastered setup, int offsetX) {
final SpriteAnimated surface = Drawable.loadSpriteAnimated(setup.getSurface(), 4, 4);
final Featurable featurable = new FeaturableModel(services, setup);
featurable.addFeature(new MirrorableModel(services, setup));
featurable.addFeature(new AnimatableModel(services, setup, surface));
final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
final Rasterable rasterable = new RasterableModel(services, setup);
rasterable.setOrigin(Origin.MIDDLE);
rasterable.setFrameOffsets(1, 2);
featurable.addFeature(rasterable);
featurable.addFeature(new RefreshableModel(extrp -> {
transformable.setLocationY(UtilMath.sin(count) * 240);
surface.setLocation(camera, transformable);
rasterable.update(extrp);
surface.update(extrp);
}));
featurable.addFeature(new DisplayableModel(g -> rasterable.render(g)));
transformable.setLocationX(120 + offsetX);
handler.add(featurable);
}
use of com.b3dgs.lionengine.game.feature.Transformable in project lionengine by b3dgs.
the class TileCollidableModelTest method testFromBottom.
/**
* Test the collidable from bottom.
*/
@Test
void testFromBottom() {
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, -1.0);
transformable.moveLocation(1.0, 0.0, 3.0);
collidable.update(1.0);
assertEquals(map.getTile(0, 0), collided.get());
}
use of com.b3dgs.lionengine.game.feature.Transformable in project lionengine by b3dgs.
the class TileCollidableModelTest method testFromLeft.
/**
* Test the collidable from left.
*/
@Test
void testFromLeft() {
final Transformable transformable = createObject(new FeaturableModel(services, setup));
final AtomicReference<Tile> collided = new AtomicReference<>();
final TileCollidableListener listener = createListener(collided);
collidable.addListener(listener);
transformable.teleport(-1.0, 0.0);
transformable.moveLocation(1.0, 2.0, 0.0);
collidable.update(1.0);
assertEquals(map.getTile(0, 0), collided.get());
}
Aggregations