Search in sources :

Example 1 with TransformableModel

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;
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Force(com.b3dgs.lionengine.game.Force) IdentifiableModel(com.b3dgs.lionengine.game.feature.IdentifiableModel)

Example 2 with TransformableModel

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;
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) IdentifiableModel(com.b3dgs.lionengine.game.feature.IdentifiableModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 3 with TransformableModel

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());
}
Also used : ViewerMock(com.b3dgs.lionengine.ViewerMock) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Animatable(com.b3dgs.lionengine.game.feature.Animatable) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Animation(com.b3dgs.lionengine.Animation) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 4 with TransformableModel

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);
}
Also used : Medias(com.b3dgs.lionengine.Medias) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) BeforeEach(org.junit.jupiter.api.BeforeEach) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) UtilAssert.assertNull(com.b3dgs.lionengine.UtilAssert.assertNull) Graphics(com.b3dgs.lionengine.graphic.Graphics) Services(com.b3dgs.lionengine.game.feature.Services) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) Handler(com.b3dgs.lionengine.game.feature.Handler) Geom(com.b3dgs.lionengine.geom.Geom) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Camera(com.b3dgs.lionengine.game.feature.Camera) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Camera(com.b3dgs.lionengine.game.feature.Camera) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with TransformableModel

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());
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) UtilTransformable(com.b3dgs.lionengine.game.feature.UtilTransformable) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Test(org.junit.jupiter.api.Test)

Aggregations

TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)37 Test (org.junit.jupiter.api.Test)20 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)19 Transformable (com.b3dgs.lionengine.game.feature.Transformable)17 Setup (com.b3dgs.lionengine.game.feature.Setup)12 Featurable (com.b3dgs.lionengine.game.feature.Featurable)11 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)10 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)9 Media (com.b3dgs.lionengine.Media)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)5 Services (com.b3dgs.lionengine.game.feature.Services)5 UtilTransformable (com.b3dgs.lionengine.game.feature.UtilTransformable)5 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)5 Medias (com.b3dgs.lionengine.Medias)4 Handler (com.b3dgs.lionengine.game.feature.Handler)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Animation (com.b3dgs.lionengine.Animation)3 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)3 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)3