Search in sources :

Example 21 with Force

use of com.b3dgs.lionengine.game.Force in project lionengine by b3dgs.

the class UtilLaunchable method createLaunchable.

/**
 * Create launchable.
 *
 * @param services The services.
 * @param setup The setup.
 * @param featurable The featurable.
 * @return The launchable.
 */
public static Launchable createLaunchable(Services services, Setup setup, Featurable featurable) {
    featurable.addFeature(new TransformableModel(services, setup));
    final Launchable launchable = new LaunchableModel(services, setup);
    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)

Example 22 with Force

use of com.b3dgs.lionengine.game.Force in project lionengine by b3dgs.

the class TransformableModelTest method testMoveLocation.

/**
 * Test the transformable moving.
 */
@Test
void testMoveLocation() {
    assertLocalization(0.0, 0.0, 0.0, 0.0);
    transformable.backup();
    transformable.moveLocation(1.0, 1.0, 2.0);
    assertLocalization(0.0, 0.0, 1.0, 2.0);
    transformable.backup();
    transformable.moveLocation(1.0, new Force(-2.0, -3.0), new Force(-1.0, -2.0));
    assertLocalization(1.0, 2.0, -2.0, -3.0);
}
Also used : Force(com.b3dgs.lionengine.game.Force) Test(org.junit.jupiter.api.Test)

Example 23 with Force

use of com.b3dgs.lionengine.game.Force in project lionengine by b3dgs.

the class LauncherModelTest method testLauncherInitial.

/**
 * Test the launcher with initial speed.
 *
 * @throws InterruptedException If error.
 */
@Test
void testLauncherInitial() throws InterruptedException {
    final AtomicBoolean fired = new AtomicBoolean();
    final AtomicReference<Launchable> firedLaunchable = new AtomicReference<>();
    launcher.addListener(UtilLaunchable.createListener(fired));
    launcher.addListener(UtilLaunchable.createListener(firedLaunchable));
    final Force force = new Force(1.0, 2.0);
    assertTimeout(1000L, () -> {
        while (!launcher.fire(force)) {
            launcher.update(1.0);
            continue;
        }
    });
    assertTrue(fired.get());
    assertNotNull(firedLaunchable.get());
    final Transformable transformable = firedLaunchable.get().getFeature(Transformable.class);
    assertEquals(2.0, transformable.getX());
    assertEquals(4.0, transformable.getY());
    final Handler handler = services.get(Handler.class);
    handler.update(1.0);
    assertEquals(1, handler.size());
    handler.removeAll();
    handler.update(1.0);
    assertEquals(0, handler.size());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Force(com.b3dgs.lionengine.game.Force) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Handler(com.b3dgs.lionengine.game.feature.Handler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Aggregations

Force (com.b3dgs.lionengine.game.Force)23 Test (org.junit.jupiter.api.Test)11 ArrayList (java.util.ArrayList)4 Media (com.b3dgs.lionengine.Media)3 Xml (com.b3dgs.lionengine.Xml)3 Test (org.junit.Test)3 Transformable (com.b3dgs.lionengine.game.feature.Transformable)2 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)2 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)2 Configurer (com.b3dgs.lionengine.game.Configurer)1 Handler (com.b3dgs.lionengine.game.feature.Handler)1 IdentifiableModel (com.b3dgs.lionengine.game.feature.IdentifiableModel)1 Mirrorable (com.b3dgs.lionengine.game.feature.Mirrorable)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1