use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.
the class UtilLaunchable method createLaunchable.
/**
* Create launchable.
*
* @param services The services.
* @param featurable The featurable.
* @return The launchable.
*/
public static Launchable createLaunchable(Services services, Featurable featurable) {
featurable.addFeature(new IdentifiableModel());
featurable.addFeature(new TransformableModel());
final Launchable launchable = new LaunchableModel();
launchable.prepare(featurable);
launchable.setLocation(0.0, 0.0);
launchable.setVector(new Force(0.0, 1.0));
return launchable;
}
use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.
the class UtilExtractable method createExtractable.
/**
* Create extractable.
*
* @return The extractable.
*/
public static Extractable createExtractable() {
final Services services = new Services();
services.add(new MapTileGame());
final Featurable featurable = new FeaturableModel();
featurable.addFeature(new IdentifiableModel());
featurable.addFeature(new TransformableModel());
final Extractable extractable = new ExtractableModel(services);
extractable.setResourcesQuantity(10);
extractable.setResourcesType(ResourceType.WOOD);
extractable.prepare(featurable);
return extractable;
}
use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.
the class RasterableModelTest method testModel.
/**
* Test the model.
*/
@Test
void testModel() {
services.add(new ViewerMock());
final SetupSurfaceRastered setup = new SetupSurfaceRastered(Medias.create(OBJECT_XML));
final Featurable featurable = new FeaturableModel(services, setup);
final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
final Animatable animatable = featurable.addFeatureAndGet(new AnimatableModel(services, setup));
featurable.addFeature(new MirrorableModel(services, setup));
final Rasterable rasterable = new RasterableModel(services, setup);
rasterable.setFrameOffsets(1, 2);
rasterable.prepare(featurable);
rasterable.setOrigin(Origin.TOP_LEFT);
rasterable.update(1.0);
rasterable.setEnabled(false);
rasterable.update(1.0);
rasterable.render(g);
assertTrue(rasterable.isVisible());
rasterable.setVisibility(false);
rasterable.update(1.0);
rasterable.render(g);
assertFalse(rasterable.isVisible());
assertEquals(1, rasterable.getRasterIndex(0));
assertEquals(RasterImage.MAX_RASTERS, rasterable.getRasterIndex(240));
assertNotNull(rasterable.getRasterAnim(0));
transformable.teleportY(-100);
rasterable.update(1.0);
assertEquals(1, rasterable.getRasterIndex(0));
assertEquals(RasterImage.MAX_RASTERS, rasterable.getRasterIndex(240));
assertNotNull(rasterable.getRasterAnim(0));
animatable.play(new Animation("default", 1, 5, 1.0, false, false));
animatable.update(1.0);
rasterable.update(1.0);
assertEquals(1, rasterable.getRasterAnim(0).getFrame());
rasterable.setAnimOffset(1);
rasterable.update(1.0);
assertEquals(1, rasterable.getRasterAnim(0).getFrame());
}
use of com.b3dgs.lionengine.game.feature.TransformableModel in project lionengine by b3dgs.
the class ComponentCollisionTest method prepare.
/**
* Prepare test.
*/
@BeforeEach
public void prepare() {
services.add(new Camera());
featurable1 = new ObjectSelf(services, setup);
transformable1 = featurable1.addFeatureAndGet(new TransformableModel(services, setup));
collidable1 = featurable1.addFeatureAndGet(new CollidableModel(services, setup));
collidable1.setGroup(Integer.valueOf(1));
collidable1.addAccept(Integer.valueOf(0));
final Collision collision1 = new Collision("test1", 0, 0, 3, 3, false);
collidable1.addCollision(collision1);
featurable2 = CollidableModelTest.createFeaturable(config, services);
transformable2 = featurable2.getFeature(Transformable.class);
collidable2 = featurable2.getFeature(Collidable.class);
collidable2.addAccept(Integer.valueOf(1));
collidable2.setGroup(Integer.valueOf(0));
featurable1.addFeature(new MirrorableModel(services, setup));
featurable2.addFeature(new MirrorableModel(services, setup));
final Collision collision2 = new Collision("test2", 0, 0, 3, 3, true);
collidable2.addCollision(collision2);
handler.addComponent(component);
handler.add(featurable1);
handler.add(featurable2);
handler.add(nonCollidable);
final CollidableListener listener = (collidable, with, by) -> collide.set(collidable);
collidable2.addListener(listener);
}
use of com.b3dgs.lionengine.game.feature.TransformableModel 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());
}
Aggregations