Search in sources :

Example 1 with Mirrorable

use of com.b3dgs.lionengine.game.feature.Mirrorable in project lionengine by b3dgs.

the class LauncherModel method launch.

/**
 * Launch the launchable.
 *
 * @param config The launch configuration.
 * @param initial The fire launch initial direction for force transfer.
 * @param featurable The featurable representing the launchable.
 * @param launchable The launchable to launch.
 */
private void launch(LaunchableConfig config, Direction initial, Featurable featurable, Launchable launchable) {
    int sideX = 1;
    int sideY = 1;
    if (mirror && mirrorable != null) {
        if (mirrorable.is(Mirror.HORIZONTAL)) {
            sideX = -1;
        }
        if (mirrorable.is(Mirror.VERTICAL)) {
            sideY = -1;
        }
        launchable.getFeature(Mirrorable.class).mirror(mirrorable.getMirror());
    }
    final double x = transformable.getX() + (config.getOffsetX() + offsetX) * sideX;
    final double y = transformable.getY() + (config.getOffsetY() + offsetY) * sideY;
    launchable.setLocation(x, y);
    final Force vector = new Force(config.getVector());
    vector.addDirection(1.0, initial);
    final Force v = computeVector(vector);
    if (!v.isZero()) {
        launchable.setVector(v);
    }
    launchable.launch();
    config.getSfx().ifPresent(audioPlayer);
    for (final LaunchableListener listener : listenersLaunchable) {
        listener.notifyFired(launchable);
    }
    handler.add(featurable);
}
Also used : Force(com.b3dgs.lionengine.game.Force) Mirrorable(com.b3dgs.lionengine.game.feature.Mirrorable)

Example 2 with Mirrorable

use of com.b3dgs.lionengine.game.feature.Mirrorable in project lionengine by b3dgs.

the class CollidableModelTest method testMirror.

/**
 * Test collidable class with mirror.
 */
@Test
void testMirror() {
    final Mirrorable mirror1 = featurable1.addFeatureAndGet(new MirrorableModel(services, setup));
    mirror1.mirror(Mirror.HORIZONTAL);
    mirror1.update(1.0);
    final Mirrorable mirror2 = featurable2.addFeatureAndGet(new MirrorableModel(services, setup));
    mirror2.mirror(Mirror.VERTICAL);
    mirror2.update(1.0);
    final Collision collision1 = new Collision("test1", 1, 1, 1, 1, true);
    collidable1.addCollision(collision1);
    final Collision collision2 = new Collision("test2", 0, 0, 3, 3, true);
    collidable2.addCollision(collision2);
    transformable1.teleport(0.0, 0.0);
    transformable2.moveLocation(0.0, 0.0, 0.0);
    assertTrue(collidable1.collide(collidable2).isEmpty());
    assertTrue(collidable2.collide(collidable1).isEmpty());
    transformable1.teleport(1.5, 2.5);
    assertEquals(Arrays.asList(new CollisionCouple(collision1, collision2)), collidable1.collide(collidable2));
    assertEquals(Arrays.asList(new CollisionCouple(collision2, collision1)), collidable2.collide(collidable1));
}
Also used : MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Mirrorable(com.b3dgs.lionengine.game.feature.Mirrorable) Test(org.junit.jupiter.api.Test)

Aggregations

Mirrorable (com.b3dgs.lionengine.game.feature.Mirrorable)2 Force (com.b3dgs.lionengine.game.Force)1 MirrorableModel (com.b3dgs.lionengine.game.feature.MirrorableModel)1 Test (org.junit.jupiter.api.Test)1