Search in sources :

Example 6 with Services

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

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

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

the class SceneRasterable method add.

private void add(SetupSurfaceRastered setup, int offsetX) {
    final SpriteAnimated surface = Drawable.loadSpriteAnimated(setup.getSurface(), 4, 4);
    final Featurable featurable = new FeaturableModel(services, setup);
    featurable.addFeature(new MirrorableModel(services, setup));
    featurable.addFeature(new AnimatableModel(services, setup, surface));
    final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
    final Rasterable rasterable = new RasterableModel(services, setup);
    rasterable.setOrigin(Origin.MIDDLE);
    rasterable.setFrameOffsets(1, 2);
    featurable.addFeature(rasterable);
    featurable.addFeature(new RefreshableModel(extrp -> {
        transformable.setLocationY(UtilMath.sin(count) * 240);
        surface.setLocation(camera, transformable);
        rasterable.update(extrp);
        surface.update(extrp);
    }));
    featurable.addFeature(new DisplayableModel(g -> rasterable.render(g)));
    transformable.setLocationX(120 + offsetX);
    handler.add(featurable);
}
Also used : Medias(com.b3dgs.lionengine.Medias) ComponentRefreshable(com.b3dgs.lionengine.game.feature.ComponentRefreshable) RefreshableModel(com.b3dgs.lionengine.game.feature.RefreshableModel) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) ComponentDisplayable(com.b3dgs.lionengine.game.feature.ComponentDisplayable) Drawable(com.b3dgs.lionengine.graphic.drawable.Drawable) Resolution(com.b3dgs.lionengine.Resolution) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) Services(com.b3dgs.lionengine.game.feature.Services) RasterableModel(com.b3dgs.lionengine.game.feature.rasterable.RasterableModel) SetupSurfaceRastered(com.b3dgs.lionengine.game.feature.rasterable.SetupSurfaceRastered) Handler(com.b3dgs.lionengine.game.feature.Handler) UtilMath(com.b3dgs.lionengine.UtilMath) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Rasterable(com.b3dgs.lionengine.game.feature.rasterable.Rasterable) Graphic(com.b3dgs.lionengine.graphic.Graphic) Sequence(com.b3dgs.lionengine.graphic.engine.Sequence) DisplayableModel(com.b3dgs.lionengine.game.feature.DisplayableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Engine(com.b3dgs.lionengine.Engine) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Context(com.b3dgs.lionengine.Context) Tick(com.b3dgs.lionengine.Tick) Origin(com.b3dgs.lionengine.Origin) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Camera(com.b3dgs.lionengine.game.feature.Camera) SpriteAnimated(com.b3dgs.lionengine.graphic.drawable.SpriteAnimated) RefreshableModel(com.b3dgs.lionengine.game.feature.RefreshableModel) DisplayableModel(com.b3dgs.lionengine.game.feature.DisplayableModel) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) RasterableModel(com.b3dgs.lionengine.game.feature.rasterable.RasterableModel) SpriteAnimated(com.b3dgs.lionengine.graphic.drawable.SpriteAnimated) Transformable(com.b3dgs.lionengine.game.feature.Transformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Rasterable(com.b3dgs.lionengine.game.feature.rasterable.Rasterable) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 9 with Services

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

the class DeviceControllerConfig method create.

/**
 * Create device controller from configuration.
 *
 * @param services The services reference (must not be <code>null</code>).
 * @param media The media configuration (must not be <code>null</code>).
 * @return The created controller.
 * @throws LionEngineException If unable to read node.
 */
public static DeviceController create(Services services, Media media) {
    final Context context = services.get(Context.class);
    final DeviceController controller = new DeviceControllerModel();
    final Collection<DeviceControllerConfig> configs = DeviceControllerConfig.imports(services, media);
    for (final DeviceControllerConfig config : configs) {
        final InputDevice device = context.getInputDevice(config.getDevice());
        if (device instanceof DevicePush) {
            final DevicePush push = (DevicePush) device;
            config.getHorizontal().forEach(h -> controller.addHorizontal(push, new DeviceActionModel(h, push)));
            config.getVertical().forEach(v -> controller.addVertical(push, new DeviceActionModel(v, push)));
            config.getFire().entrySet().forEach(e -> e.getValue().forEach(c -> controller.addFire(device, e.getKey(), new DeviceActionModel(c, push))));
        }
        if (device instanceof DevicePointer) {
            final DevicePointer pointer = (DevicePointer) device;
            controller.addHorizontal(pointer, () -> pointer.getMoveX());
            controller.addVertical(pointer, () -> -pointer.getMoveY());
        }
        if (config.isDisabled()) {
            controller.setDisabled(device.getName(), true, true);
        }
    }
    return controller;
}
Also used : Context(com.b3dgs.lionengine.Context) DevicePush(com.b3dgs.lionengine.io.DevicePush) LionEngineException(com.b3dgs.lionengine.LionEngineException) DevicePointer(com.b3dgs.lionengine.io.DevicePointer) DevicePush(com.b3dgs.lionengine.io.DevicePush) Collection(java.util.Collection) Check(com.b3dgs.lionengine.Check) Set(java.util.Set) HashMap(java.util.HashMap) DeviceControllerModel(com.b3dgs.lionengine.io.DeviceControllerModel) DeviceController(com.b3dgs.lionengine.io.DeviceController) Configurer(com.b3dgs.lionengine.game.Configurer) DeviceMapper(com.b3dgs.lionengine.io.DeviceMapper) ArrayList(java.util.ArrayList) InputDevice(com.b3dgs.lionengine.InputDevice) HashSet(java.util.HashSet) Constant(com.b3dgs.lionengine.Constant) Context(com.b3dgs.lionengine.Context) DeviceAxis(com.b3dgs.lionengine.io.DeviceAxis) List(java.util.List) XmlReader(com.b3dgs.lionengine.XmlReader) Services(com.b3dgs.lionengine.game.feature.Services) Map(java.util.Map) Media(com.b3dgs.lionengine.Media) DeviceActionModel(com.b3dgs.lionengine.io.DeviceActionModel) DeviceControllerModel(com.b3dgs.lionengine.io.DeviceControllerModel) InputDevice(com.b3dgs.lionengine.InputDevice) DeviceController(com.b3dgs.lionengine.io.DeviceController) DevicePointer(com.b3dgs.lionengine.io.DevicePointer) DeviceActionModel(com.b3dgs.lionengine.io.DeviceActionModel)

Example 10 with Services

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

the class EntityHelper method addAfter.

/*
     * Featurable
     */
@Override
public void addAfter(Services services, Setup setup) {
    final Routines routines = addFeatureAndGet(new Routines(services, setup));
    updating = extrp -> {
        state.update(extrp);
        attacker.update(extrp);
        extractor.update(extrp);
        producer.update(extrp);
        launchable.update(extrp);
        launcher.update(extrp);
        routines.update(extrp);
        body.update(extrp);
        pathfindable.update(extrp);
        tileCollidable.update(extrp);
        state.postUpdate();
        mirrorable.update(extrp);
        animatable.update(extrp);
        rasterable.update(extrp);
    };
    rendering = g -> {
        pathfindable.render(g);
        rasterable.render(g);
        collidable.render(g);
        routines.render(g);
    };
    updatingCurrent = updating;
    renderingCurrent = rendering;
    addFeature(new RefreshableModel(extrp -> {
        checker.update(extrp);
        updatingCurrent.update(extrp);
    }));
    addFeature(new DisplayableModel(g -> {
        renderingCurrent.render(g);
    }));
}
Also used : Routines(com.b3dgs.lionengine.game.feature.Routines) State(com.b3dgs.lionengine.game.feature.state.State) RefreshableModel(com.b3dgs.lionengine.game.feature.RefreshableModel) Routines(com.b3dgs.lionengine.game.feature.Routines) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) ProducibleModel(com.b3dgs.lionengine.game.feature.producible.ProducibleModel) Setup(com.b3dgs.lionengine.game.feature.Setup) RenderableVoid(com.b3dgs.lionengine.graphic.RenderableVoid) AttackerModel(com.b3dgs.lionengine.game.feature.attackable.AttackerModel) FovableModel(com.b3dgs.lionengine.game.feature.tile.map.transition.fog.FovableModel) SelectableModel(com.b3dgs.lionengine.game.feature.collidable.selector.SelectableModel) Mirrorable(com.b3dgs.lionengine.game.feature.Mirrorable) TileCollidable(com.b3dgs.lionengine.game.feature.tile.map.collision.TileCollidable) PathfindableModel(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.PathfindableModel) LaunchableModel(com.b3dgs.lionengine.game.feature.launchable.LaunchableModel) Attacker(com.b3dgs.lionengine.game.feature.attackable.Attacker) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) Body(com.b3dgs.lionengine.game.feature.body.Body) ActionerModel(com.b3dgs.lionengine.game.feature.ActionerModel) Services(com.b3dgs.lionengine.game.feature.Services) RasterableModel(com.b3dgs.lionengine.game.feature.rasterable.RasterableModel) Extractor(com.b3dgs.lionengine.game.feature.tile.map.extractable.Extractor) UpdatableVoid(com.b3dgs.lionengine.UpdatableVoid) SetupSurfaceRastered(com.b3dgs.lionengine.game.feature.rasterable.SetupSurfaceRastered) Locale(java.util.Locale) ProducerModel(com.b3dgs.lionengine.game.feature.producible.ProducerModel) Animatable(com.b3dgs.lionengine.game.feature.Animatable) Producer(com.b3dgs.lionengine.game.feature.producible.Producer) CollidableFramedModel(com.b3dgs.lionengine.game.feature.collidable.framed.CollidableFramedModel) CollidableModel(com.b3dgs.lionengine.game.feature.collidable.CollidableModel) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Renderable(com.b3dgs.lionengine.graphic.Renderable) Rasterable(com.b3dgs.lionengine.game.feature.rasterable.Rasterable) Collidable(com.b3dgs.lionengine.game.feature.collidable.Collidable) Launchable(com.b3dgs.lionengine.game.feature.launchable.Launchable) ExtractableModel(com.b3dgs.lionengine.game.feature.tile.map.extractable.ExtractableModel) DisplayableModel(com.b3dgs.lionengine.game.feature.DisplayableModel) Updatable(com.b3dgs.lionengine.Updatable) Launcher(com.b3dgs.lionengine.game.feature.launchable.Launcher) LayerableModel(com.b3dgs.lionengine.game.feature.LayerableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Pathfindable(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable) BodyModel(com.b3dgs.lionengine.game.feature.body.BodyModel) LauncherModel(com.b3dgs.lionengine.game.feature.launchable.LauncherModel) TileCollidableModel(com.b3dgs.lionengine.game.feature.tile.map.collision.TileCollidableModel) StateHandler(com.b3dgs.lionengine.game.feature.state.StateHandler) ExtractorModel(com.b3dgs.lionengine.game.feature.tile.map.extractable.ExtractorModel) RefreshableModel(com.b3dgs.lionengine.game.feature.RefreshableModel) DisplayableModel(com.b3dgs.lionengine.game.feature.DisplayableModel)

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