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