Search in sources :

Example 1 with FeaturableModel

use of com.b3dgs.lionengine.game.feature.FeaturableModel 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();
    featurable.addFeature(new IdentifiableModel());
    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) IdentifiableModel(com.b3dgs.lionengine.game.feature.IdentifiableModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 2 with FeaturableModel

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

the class UtilAssignable method createAssignable.

/**
 * Create the assignable.
 *
 * @param services The services.
 * @return The prepared assignable.
 */
public static AssignableModel createAssignable(Services services) {
    final Featurable featurable = new FeaturableModel();
    featurable.addFeature(new IdentifiableModel());
    final AssignableModel assignable = new AssignableModel(services);
    assignable.prepare(featurable);
    return assignable;
}
Also used : FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) IdentifiableModel(com.b3dgs.lionengine.game.feature.IdentifiableModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 3 with FeaturableModel

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

the class SceneRasterable method load.

@Override
public void load() {
    final SetupSurfaceRastered setup = new SetupSurfaceRastered(Medias.create("object.xml"), Medias.create("raster.xml"));
    final SpriteAnimated surface = Drawable.loadSpriteAnimated(setup.getSurface(), 4, 4);
    final Featurable featurable = new FeaturableModel();
    featurable.addFeature(new MirrorableModel());
    featurable.addFeature(new AnimatableModel(surface));
    final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel());
    final Rasterable rasterable = new RasterableModel(services, setup);
    rasterable.setOrigin(Origin.MIDDLE);
    featurable.addFeature(rasterable);
    featurable.addFeature(new RefreshableModel(extrp -> {
        transformable.setLocationY(UtilMath.sin(count * 3) * 240);
        surface.setLocation(camera, transformable);
        rasterable.update(extrp);
        surface.update(extrp);
    }));
    featurable.addFeature(new DisplayableModel(g -> rasterable.render(g)));
    transformable.setLocationX(120);
    handler.add(featurable);
    camera.setView(0, 0, getWidth(), getHeight(), getHeight());
    timing.start();
}
Also used : 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) Engine(com.b3dgs.lionengine.core.Engine) Timing(com.b3dgs.lionengine.Timing) 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) Medias(com.b3dgs.lionengine.core.Medias) Drawable(com.b3dgs.lionengine.core.drawable.Drawable) Handler(com.b3dgs.lionengine.game.feature.Handler) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Rasterable(com.b3dgs.lionengine.game.feature.rasterable.Rasterable) Graphic(com.b3dgs.lionengine.graphic.Graphic) DisplayableModel(com.b3dgs.lionengine.game.feature.DisplayableModel) SpriteAnimated(com.b3dgs.lionengine.graphic.SpriteAnimated) Sequence(com.b3dgs.lionengine.core.sequence.Sequence) Transformable(com.b3dgs.lionengine.game.feature.Transformable) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Context(com.b3dgs.lionengine.Context) UtilMath(com.b3dgs.lionengine.util.UtilMath) Origin(com.b3dgs.lionengine.Origin) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Camera(com.b3dgs.lionengine.game.feature.Camera) RefreshableModel(com.b3dgs.lionengine.game.feature.RefreshableModel) DisplayableModel(com.b3dgs.lionengine.game.feature.DisplayableModel) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Rasterable(com.b3dgs.lionengine.game.feature.rasterable.Rasterable) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) RasterableModel(com.b3dgs.lionengine.game.feature.rasterable.RasterableModel) SetupSurfaceRastered(com.b3dgs.lionengine.game.feature.rasterable.SetupSurfaceRastered) SpriteAnimated(com.b3dgs.lionengine.graphic.SpriteAnimated) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 4 with FeaturableModel

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

the class ProducerModelTest method testDefaultProduction.

/**
 * Test the default production with default checker.
 */
@Test
public void testDefaultProduction() {
    final ProducerModel producer = new ProducerModel(services);
    producer.prepare(new FeaturableModel());
    producer.setStepsPerSecond(25.0);
    final AtomicReference<Featurable> start = new AtomicReference<>();
    final AtomicReference<Featurable> current = new AtomicReference<>();
    final AtomicReference<Featurable> done = new AtomicReference<>();
    final AtomicReference<Featurable> cant = new AtomicReference<>();
    producer.addListener(UtilProducible.createProducerListener(start, current, done, cant));
    producer.update(1.0);
    Assert.assertNull(producer.getProducingElement());
    Assert.assertEquals(-1.0, producer.getProgress(), UtilTests.PRECISION);
    Assert.assertEquals(-1, producer.getProgressPercent());
    Assert.assertEquals(0, producer.getQueueLength());
    Assert.assertFalse(producer.isProducing());
    final Featurable featurable = UtilProducible.createProducible(services);
    producer.addToProductionQueue(featurable);
    Assert.assertEquals(0, producer.getQueueLength());
    Assert.assertNull(start.get());
    Assert.assertFalse(producer.isProducing());
    producer.update(1.0);
    Assert.assertEquals(0.0, producer.getProgress(), UtilTests.PRECISION);
    Assert.assertEquals(0, producer.getProgressPercent());
    Assert.assertEquals(0, producer.getQueueLength());
    Assert.assertEquals(featurable, start.get());
    Assert.assertNull(current.get());
    Assert.assertTrue(producer.isProducing());
    Assert.assertEquals(featurable.getFeature(Producible.class).getMedia(), producer.getProducingElement());
    producer.update(1.0);
    Assert.assertEquals(0.5, producer.getProgress(), UtilTests.PRECISION);
    Assert.assertEquals(50, producer.getProgressPercent());
    Assert.assertEquals(featurable, current.get());
    Assert.assertNull(done.get());
    Assert.assertTrue(producer.isProducing());
    producer.update(1.0);
    Assert.assertEquals(1.0, producer.getProgress(), UtilTests.PRECISION);
    Assert.assertEquals(100, producer.getProgressPercent());
    Assert.assertEquals(featurable, current.get());
    Assert.assertNull(done.get());
    Assert.assertFalse(producer.isProducing());
    producer.update(1.0);
    Assert.assertEquals(featurable, done.get());
    Assert.assertNull(cant.get());
    Assert.assertFalse(producer.isProducing());
}
Also used : FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.Test)

Example 5 with FeaturableModel

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

the class ProducibleModelTest method testProducible.

/**
 * Test the producible.
 */
@Test
public void testProducible() {
    final Media media = UtilProducible.createProducibleMedia();
    final Setup setup = new Setup(media);
    final Featurable featurable = new FeaturableModel();
    featurable.addFeature(new IdentifiableModel());
    final Producible producible = new ProducibleModel(setup);
    final ProducibleListener listener = UtilProducible.createListener();
    producible.setLocation(1.0, 2.0);
    producible.prepare(featurable);
    producible.addListener(listener);
    Assert.assertEquals(media, producible.getMedia());
    Assert.assertEquals(1, producible.getSteps());
    Assert.assertEquals(2, producible.getWidth());
    Assert.assertEquals(3, producible.getHeight());
    Assert.assertEquals(1.0, producible.getX(), UtilTests.PRECISION);
    Assert.assertEquals(2.0, producible.getY(), UtilTests.PRECISION);
    Assert.assertTrue(producible.getListeners().contains(listener));
    producible.getFeature(Identifiable.class).notifyDestroyed();
    Assert.assertTrue(media.getFile().delete());
}
Also used : Media(com.b3dgs.lionengine.Media) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) IdentifiableModel(com.b3dgs.lionengine.game.feature.IdentifiableModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.Test)

Aggregations

FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)21 Transformable (com.b3dgs.lionengine.game.feature.Transformable)13 Test (org.junit.Test)12 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)11 Featurable (com.b3dgs.lionengine.game.feature.Featurable)10 Setup (com.b3dgs.lionengine.game.feature.Setup)9 MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)8 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)6 IdentifiableModel (com.b3dgs.lionengine.game.feature.IdentifiableModel)5 Services (com.b3dgs.lionengine.game.feature.Services)5 Media (com.b3dgs.lionengine.Media)2 Camera (com.b3dgs.lionengine.game.feature.Camera)2 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)2 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)2 Context (com.b3dgs.lionengine.Context)1 Origin (com.b3dgs.lionengine.Origin)1 Resolution (com.b3dgs.lionengine.Resolution)1 Timing (com.b3dgs.lionengine.Timing)1