Search in sources :

Example 6 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.
 * @param setup The setup.
 * @return The prepared assignable.
 */
public static AssignableModel createAssignable(Services services, Setup setup) {
    final Featurable featurable = new FeaturableModel(services, setup);
    final AssignableModel assignable = new AssignableModel(services, setup);
    assignable.prepare(featurable);
    return assignable;
}
Also used : FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 7 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(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 8 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
void testDefaultProduction() {
    final ProducerModel producer = new ProducerModel(services, setup);
    producer.prepare(new FeaturableModel(services, setup));
    producer.recycle();
    producer.setStepsSpeed(0.5);
    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);
    assertNull(producer.getProducingElement());
    assertEquals(-1.0, producer.getProgress());
    assertEquals(-1, producer.getProgressPercent());
    assertEquals(0, producer.getQueueLength());
    assertFalse(producer.isProducing());
    final Featurable featurable = UtilProducible.createProducible(services);
    producer.addToProductionQueue(featurable);
    assertEquals(0, producer.getQueueLength());
    assertNull(start.get());
    assertFalse(producer.isProducing());
    producer.update(1.0);
    assertEquals(0.0, producer.getProgress());
    assertEquals(0, producer.getProgressPercent());
    assertEquals(0, producer.getQueueLength());
    assertEquals(featurable, start.get());
    assertNull(current.get());
    assertTrue(producer.isProducing());
    assertEquals(featurable, producer.getProducingElement());
    producer.update(1.0);
    assertEquals(0.5, producer.getProgress());
    assertEquals(50, producer.getProgressPercent());
    assertEquals(featurable, current.get());
    assertNull(done.get());
    assertTrue(producer.isProducing());
    producer.update(1.0);
    assertEquals(1.0, producer.getProgress());
    assertEquals(100, producer.getProgressPercent());
    assertEquals(featurable, current.get());
    assertNull(done.get());
    assertFalse(producer.isProducing());
    producer.update(1.0);
    assertEquals(featurable, done.get());
    assertNull(cant.get());
    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.jupiter.api.Test)

Example 9 with FeaturableModel

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

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

the class TileCollidableModelTest method testFromBottom.

/**
 * Test the collidable from bottom.
 */
@Test
void testFromBottom() {
    final Transformable transformable = createObject(new FeaturableModel(services, setup));
    final AtomicReference<Tile> collided = new AtomicReference<>();
    final TileCollidableListener listener = createListener(collided);
    collidable.addListener(listener);
    transformable.teleport(0.0, -1.0);
    transformable.moveLocation(1.0, 0.0, 3.0);
    collidable.update(1.0);
    assertEquals(map.getTile(0, 0), collided.get());
}
Also used : Transformable(com.b3dgs.lionengine.game.feature.Transformable) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Aggregations

FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)33 Test (org.junit.jupiter.api.Test)20 Featurable (com.b3dgs.lionengine.game.feature.Featurable)18 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)18 Transformable (com.b3dgs.lionengine.game.feature.Transformable)16 Setup (com.b3dgs.lionengine.game.feature.Setup)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)7 Media (com.b3dgs.lionengine.Media)6 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)6 Services (com.b3dgs.lionengine.game.feature.Services)5 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)5 Medias (com.b3dgs.lionengine.Medias)4 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)4 Animation (com.b3dgs.lionengine.Animation)3 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)3 UtilAssert.assertTrue (com.b3dgs.lionengine.UtilAssert.assertTrue)3 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)3 UtilTransformable (com.b3dgs.lionengine.game.feature.UtilTransformable)3 MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)3