Search in sources :

Example 11 with Setup

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

the class CollidableModelTest method testDifferentSizes.

/**
 * Test collidable class with different sizes.
 */
@Test
void testDifferentSizes() {
    featurable1.addFeature(new MirrorableModel(services, setup));
    featurable2.addFeature(new MirrorableModel(services, setup));
    final AtomicBoolean auto = new AtomicBoolean();
    collidable1.checkListener((CollidableListener) (collidable, with, by) -> auto.set(true));
    final Collision collision1 = new Collision("test1", 1, 1, 1, 1, true);
    final Collision collision2 = new Collision("test2", 0, 0, 3, 3, false);
    collidable1.notifyCollided(collidable2, collision1, collision2);
    assertTrue(auto.get());
    collidable1.addCollision(collision1);
    collidable2.addCollision(collision2);
    transformable1.moveLocation(1.0, 1, 1);
    transformable2.moveLocation(1.0, 0, 0);
    assertEquals(Arrays.asList(new CollisionCouple(collision2, collision1)), collidable2.collide(collidable1));
    transformable1.teleport(0.5, 3.5);
    assertEquals(Arrays.asList(new CollisionCouple(collision2, collision1)), collidable2.collide(collidable1));
}
Also used : Medias(com.b3dgs.lionengine.Medias) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) UtilAssert.assertFalse(com.b3dgs.lionengine.UtilAssert.assertFalse) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Mirrorable(com.b3dgs.lionengine.game.feature.Mirrorable) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) AfterAll(org.junit.jupiter.api.AfterAll) Graphics(com.b3dgs.lionengine.graphic.Graphics) Services(com.b3dgs.lionengine.game.feature.Services) UtilAssert.assertNotNull(com.b3dgs.lionengine.UtilAssert.assertNotNull) BeforeAll(org.junit.jupiter.api.BeforeAll) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) UtilAssert.assertPrivateConstructor(com.b3dgs.lionengine.UtilAssert.assertPrivateConstructor) Graphic(com.b3dgs.lionengine.graphic.Graphic) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Test(org.junit.jupiter.api.Test) Mirror(com.b3dgs.lionengine.Mirror) AfterEach(org.junit.jupiter.api.AfterEach) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) Origin(com.b3dgs.lionengine.Origin) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Camera(com.b3dgs.lionengine.game.feature.Camera) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Test(org.junit.jupiter.api.Test)

Example 12 with Setup

use of com.b3dgs.lionengine.game.feature.Setup 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 13 with Setup

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

the class UtilActionnable method createActionable.

/**
 * Create the actionable.
 *
 * @param media The media.
 * @param services The services.
 * @return The prepared actionable.
 */
public static ActionableModel createActionable(Media media, Services services) {
    final Setup setup = new Setup(media);
    final Featurable featurable = new FeaturableModel(services, setup);
    final ActionableModel actionable = new ActionableModel(services, setup);
    actionable.prepare(featurable);
    return actionable;
}
Also used : ActionableModel(com.b3dgs.lionengine.game.feature.ActionableModel) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 14 with Setup

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

the class AttackerModelTest method testNoConfig.

/**
 * Test without config.
 */
@Test
void testNoConfig() {
    final Media media = UtilTransformable.createMedia(AttackerModelTest.class);
    final Xml xml = new Xml(media);
    xml.save(media);
    final AttackerModel attacker = new AttackerModel(services, new Setup(media));
    assertTrue(attacker.getAttackDamages() == 0);
    assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Test(org.junit.jupiter.api.Test)

Example 15 with Setup

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

the class LauncherModelTest method testLauncherException.

/**
 * Test the launcher failure.
 */
@Test
void testLauncherException() {
    final Media launchableMedia = UtilSetup.createMedia(LaunchableObjectException.class);
    final Media launcherMedia = UtilLaunchable.createLauncherMedia(launchableMedia);
    final Setup setup = new Setup(launcherMedia);
    final Launcher launcher = UtilLaunchable.createLauncher(services, setup, featurable);
    try {
        assertThrowsTimeout(1000L, () -> {
            while (!launcher.fire()) {
                launcher.update(1.0);
                continue;
            }
        }, "Feature not found: " + Launchable.class.getName());
    } finally {
        final Handler handler = services.get(Handler.class);
        handler.removeAll();
        handler.update(1.0);
        assertEquals(0, handler.size());
        assertTrue(launchableMedia.getFile().delete());
    }
}
Also used : Media(com.b3dgs.lionengine.Media) Handler(com.b3dgs.lionengine.game.feature.Handler) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Test(org.junit.jupiter.api.Test)

Aggregations

Setup (com.b3dgs.lionengine.game.feature.Setup)42 Test (org.junit.jupiter.api.Test)34 Media (com.b3dgs.lionengine.Media)31 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)20 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)18 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)15 Xml (com.b3dgs.lionengine.Xml)11 Featurable (com.b3dgs.lionengine.game.feature.Featurable)11 Transformable (com.b3dgs.lionengine.game.feature.Transformable)11 Services (com.b3dgs.lionengine.game.feature.Services)10 Medias (com.b3dgs.lionengine.Medias)6 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)6 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)6 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)6 Handler (com.b3dgs.lionengine.game.feature.Handler)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 AfterAll (org.junit.jupiter.api.AfterAll)5 BeforeAll (org.junit.jupiter.api.BeforeAll)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 UtilAssert.assertFalse (com.b3dgs.lionengine.UtilAssert.assertFalse)4