Search in sources :

Example 11 with Services

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

the class UtilActionnable method createServices.

/**
 * Create the services.
 *
 * @param clicked The click flag.
 * @param clickNumber The click number recorded.
 * @return The services.
 */
public static Services createServices(final AtomicBoolean clicked, final AtomicInteger clickNumber) {
    final Services services = new Services();
    final Cursor cursor = new Cursor() {

        @Override
        public boolean hasClickedOnce(int click) {
            clickNumber.set(click);
            return clicked.get();
        }
    };
    cursor.setArea(0, 0, 32, 32);
    cursor.setLocation(0, 1);
    services.add(cursor);
    return services;
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) Cursor(com.b3dgs.lionengine.game.Cursor)

Example 12 with Services

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

the class UtilAssignable method createServices.

/**
 * Create the services.
 *
 * @param clicked The click flag.
 * @param clickNumber The click number recorded.
 * @return The services.
 */
public static Services createServices(final AtomicBoolean clicked, final AtomicInteger clickNumber) {
    final Services services = new Services();
    final Camera camera = services.create(Camera.class);
    camera.setView(0, 0, 32, 32, 32);
    final Cursor cursor = services.add(new Cursor() {

        @Override
        public boolean hasClickedOnce(int click) {
            clickNumber.set(click);
            return clicked.get();
        }
    });
    cursor.setArea(0, 0, 64, 64);
    cursor.setLocation(0, 1);
    return services;
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) Camera(com.b3dgs.lionengine.game.feature.Camera) Cursor(com.b3dgs.lionengine.game.Cursor)

Example 13 with Services

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

the class UtilActionnable method createServices.

/**
 * Create the services.
 *
 * @param clicked The click flag.
 * @param clickNumber The click number recorded.
 * @return The services.
 */
public static Services createServices(AtomicBoolean clicked, AtomicReference<Integer> clickNumber) {
    final Services services = new Services();
    services.add(new ContextMock());
    final Cursor cursor = new Cursor(services) {

        @Override
        public boolean isPushedOnce(Integer click) {
            clickNumber.set(click);
            return clicked.get();
        }
    };
    cursor.setArea(0, 0, 32, 32);
    cursor.setLocation(0, 1);
    services.add(cursor);
    return services;
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) ContextMock(com.b3dgs.lionengine.ContextMock) Cursor(com.b3dgs.lionengine.game.Cursor)

Example 14 with Services

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

the class BodyConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final Media media = Medias.create("Object.xml");
    final Xml root = new Xml("test");
    final Xml node = root.createChild(BodyConfig.NODE_BODY);
    node.writeDouble(BodyConfig.ATT_GRAVITY, 1.0);
    node.writeDouble(BodyConfig.ATT_GRAVITY_MAX, 2.0);
    root.save(media);
    final Body body = new BodyModel(new Services(), new Setup(media));
    BodyConfig.exports(root, body);
    final BodyConfig config = BodyConfig.imports(new Setup(media));
    assertEquals(1.0, config.getGravity());
    assertEquals(2.0, config.getGravityMax());
    assertTrue(media.getFile().delete());
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Test(org.junit.jupiter.api.Test)

Example 15 with Services

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

the class FogOfWarTest method testFogOfWar.

/**
 * Test the fog of war.
 */
@Test
void testFogOfWar() {
    final Setup setup = new Setup(config);
    final FeaturableModel object = new FeaturableModel(services, setup);
    final Transformable transformable = object.addFeatureAndGet(new TransformableModel(services, setup));
    final FovableModel fovable = object.addFeatureAndGet(new FovableModel(services, setup));
    fovable.prepare(object);
    fovable.setFov(1);
    Medias.setLoadFromJar(MapTileFog.class);
    fog.setEnabled(true, true);
    fog.create(Medias.create("fog.xml"));
    Medias.setLoadFromJar(null);
    final AtomicInteger rtx = new AtomicInteger();
    final AtomicInteger rty = new AtomicInteger();
    final AtomicInteger count = new AtomicInteger();
    final RevealedListener listener = (tx, ty) -> {
        rtx.set(tx);
        rty.set(ty);
        count.incrementAndGet();
    };
    fog.addListener(listener);
    assertFalse(fog.isFogged(2, 3));
    assertFalse(fog.isFogged(3, 3));
    assertFalse(fog.isFogged(4, 3));
    assertFalse(fog.isVisible(map.getTile(2, 3)));
    assertFalse(fog.isVisible(map.getTile(3, 3)));
    assertFalse(fog.isVisible(map.getTile(4, 3)));
    assertFalse(fog.isVisited(2, 3));
    assertFalse(fog.isVisited(3, 3));
    assertFalse(fog.isVisited(4, 3));
    assertFalse(fog.isVisited(Geom.createArea(3, 3, 1, 1)));
    transformable.teleport(3, 3);
    fog.update(fovable);
    assertTrue(fog.isFogged(2, 3));
    assertFalse(fog.isFogged(3, 3));
    assertTrue(fog.isFogged(4, 3));
    assertFalse(fog.isVisible(map.getTile(2, 3)));
    assertTrue(fog.isVisible(map.getTile(3, 3)));
    assertFalse(fog.isVisible(map.getTile(4, 3)));
    assertFalse(fog.isVisited(2, 3));
    assertTrue(fog.isVisited(3, 3));
    assertFalse(fog.isVisited(4, 3));
    assertTrue(fog.isVisited(Geom.createArea(3, 3, 1, 1)));
    assertEquals(1, count.get());
    assertEquals(3, rtx.get());
    assertEquals(3, rty.get());
    transformable.setLocation(6, 6);
    fog.removeListener(listener);
    count.set(0);
    fog.update(fovable);
    assertFalse(fog.isFogged(2, 3));
    assertTrue(fog.isFogged(3, 3));
    assertTrue(fog.isFogged(4, 3));
    assertFalse(fog.isVisible(map.getTile(2, 3)));
    assertFalse(fog.isVisible(map.getTile(3, 3)));
    assertFalse(fog.isVisible(map.getTile(4, 3)));
    assertFalse(fog.isVisited(2, 3));
    assertTrue(fog.isVisited(3, 3));
    assertFalse(fog.isVisited(4, 3));
    assertTrue(fog.isVisited(Geom.createArea(3, 3, 1, 1)));
    assertEquals(0, count.get());
    fog.setEnabled(false, false);
    assertFalse(fog.isFogged(2, 3));
    assertFalse(fog.isFogged(3, 3));
    assertFalse(fog.isFogged(4, 3));
    assertTrue(fog.isVisible(map.getTile(2, 3)));
    assertTrue(fog.isVisible(map.getTile(3, 3)));
    assertTrue(fog.isVisible(map.getTile(4, 3)));
    assertTrue(fog.isVisited(2, 3));
    assertTrue(fog.isVisited(3, 3));
    assertTrue(fog.isVisited(4, 3));
    assertTrue(fog.isVisited(Geom.createArea(3, 3, 1, 1)));
}
Also used : Medias(com.b3dgs.lionengine.Medias) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) BeforeEach(org.junit.jupiter.api.BeforeEach) UtilAssert.assertFalse(com.b3dgs.lionengine.UtilAssert.assertFalse) Graphic(com.b3dgs.lionengine.graphic.Graphic) 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) 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) UtilMap(com.b3dgs.lionengine.game.feature.tile.map.UtilMap) 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) Geom(com.b3dgs.lionengine.geom.Geom) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transformable(com.b3dgs.lionengine.game.feature.Transformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Test(org.junit.jupiter.api.Test)

Aggregations

Services (com.b3dgs.lionengine.game.feature.Services)19 Media (com.b3dgs.lionengine.Media)10 Setup (com.b3dgs.lionengine.game.feature.Setup)10 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)9 Test (org.junit.jupiter.api.Test)9 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)8 Medias (com.b3dgs.lionengine.Medias)7 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)6 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)6 Featurable (com.b3dgs.lionengine.game.feature.Featurable)6 Transformable (com.b3dgs.lionengine.game.feature.Transformable)6 Camera (com.b3dgs.lionengine.game.feature.Camera)5 AfterAll (org.junit.jupiter.api.AfterAll)5 BeforeAll (org.junit.jupiter.api.BeforeAll)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Handler (com.b3dgs.lionengine.game.feature.Handler)4 MirrorableModel (com.b3dgs.lionengine.game.feature.MirrorableModel)4 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)4 UtilAssert.assertFalse (com.b3dgs.lionengine.UtilAssert.assertFalse)3 Xml (com.b3dgs.lionengine.Xml)3