Search in sources :

Example 1 with AnimatableModel

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

the class RasterableModelTest method testModel.

/**
 * Test the model.
 */
@Test
void testModel() {
    services.add(new ViewerMock());
    final SetupSurfaceRastered setup = new SetupSurfaceRastered(Medias.create(OBJECT_XML));
    final Featurable featurable = new FeaturableModel(services, setup);
    final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
    final Animatable animatable = featurable.addFeatureAndGet(new AnimatableModel(services, setup));
    featurable.addFeature(new MirrorableModel(services, setup));
    final Rasterable rasterable = new RasterableModel(services, setup);
    rasterable.setFrameOffsets(1, 2);
    rasterable.prepare(featurable);
    rasterable.setOrigin(Origin.TOP_LEFT);
    rasterable.update(1.0);
    rasterable.setEnabled(false);
    rasterable.update(1.0);
    rasterable.render(g);
    assertTrue(rasterable.isVisible());
    rasterable.setVisibility(false);
    rasterable.update(1.0);
    rasterable.render(g);
    assertFalse(rasterable.isVisible());
    assertEquals(1, rasterable.getRasterIndex(0));
    assertEquals(RasterImage.MAX_RASTERS, rasterable.getRasterIndex(240));
    assertNotNull(rasterable.getRasterAnim(0));
    transformable.teleportY(-100);
    rasterable.update(1.0);
    assertEquals(1, rasterable.getRasterIndex(0));
    assertEquals(RasterImage.MAX_RASTERS, rasterable.getRasterIndex(240));
    assertNotNull(rasterable.getRasterAnim(0));
    animatable.play(new Animation("default", 1, 5, 1.0, false, false));
    animatable.update(1.0);
    rasterable.update(1.0);
    assertEquals(1, rasterable.getRasterAnim(0).getFrame());
    rasterable.setAnimOffset(1);
    rasterable.update(1.0);
    assertEquals(1, rasterable.getRasterAnim(0).getFrame());
}
Also used : ViewerMock(com.b3dgs.lionengine.ViewerMock) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Animatable(com.b3dgs.lionengine.game.feature.Animatable) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Animation(com.b3dgs.lionengine.Animation) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 2 with AnimatableModel

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

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

the class UtilAttackable method prepare.

/**
 * Create the featurable.
 *
 * @param featurable The featurable to prepare.
 */
public static void prepare(Featurable featurable) {
    final Animator animator = new AnimatorMock();
    animator.play(new Animation("test", 1, 1, 1.0, false, false));
    featurable.addFeature(new AnimatableModel(animator));
    featurable.addFeature(new TransformableModel());
}
Also used : Animator(com.b3dgs.lionengine.Animator) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Animation(com.b3dgs.lionengine.Animation) AnimatorMock(com.b3dgs.lionengine.core.drawable.AnimatorMock)

Example 4 with AnimatableModel

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

the class CollidableFramedModelTest method createFeaturable.

/**
 * Create a featurable test.
 *
 * @param config The configuration reference.
 * @param services The services reference.
 * @return The featurable test.
 */
public static FeaturableModel createFeaturable(Media config, Services services) {
    final Setup setup = new Setup(config);
    final FeaturableModel featurable = new FeaturableModel(services, setup);
    final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
    transformable.setLocation(1.0, 2.0);
    featurable.addFeature(new AnimatableModel(services, setup));
    featurable.addFeatureAndGet(new CollidableModel(services, setup));
    featurable.addFeature(new CollidableFramedModel(services, setup));
    return featurable;
}
Also used : CollidableModel(com.b3dgs.lionengine.game.feature.collidable.CollidableModel) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) 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)

Example 5 with AnimatableModel

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

the class UtilAttackable method prepare.

/**
 * Create the featurable.
 *
 * @param featurable The featurable to prepare.
 * @param services The services reference.
 * @param setup The setup reference.
 */
public static void prepare(Featurable featurable, Services services, Setup setup) {
    final Animator animator = new AnimatorModel();
    animator.play(new Animation("test", 1, 1, 1.0, false, false));
    featurable.addFeature(new AnimatableModel(services, setup, animator));
    featurable.addFeature(new TransformableModel(services, setup));
}
Also used : Animator(com.b3dgs.lionengine.Animator) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Animation(com.b3dgs.lionengine.Animation) AnimatorModel(com.b3dgs.lionengine.AnimatorModel)

Aggregations

AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)5 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)5 Animation (com.b3dgs.lionengine.Animation)3 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)3 Transformable (com.b3dgs.lionengine.game.feature.Transformable)3 Animator (com.b3dgs.lionengine.Animator)2 Featurable (com.b3dgs.lionengine.game.feature.Featurable)2 MirrorableModel (com.b3dgs.lionengine.game.feature.MirrorableModel)2 AnimatorModel (com.b3dgs.lionengine.AnimatorModel)1 Context (com.b3dgs.lionengine.Context)1 Engine (com.b3dgs.lionengine.Engine)1 Medias (com.b3dgs.lionengine.Medias)1 Origin (com.b3dgs.lionengine.Origin)1 Resolution (com.b3dgs.lionengine.Resolution)1 Tick (com.b3dgs.lionengine.Tick)1 UtilMath (com.b3dgs.lionengine.UtilMath)1 ViewerMock (com.b3dgs.lionengine.ViewerMock)1 AnimatorMock (com.b3dgs.lionengine.core.drawable.AnimatorMock)1 Animatable (com.b3dgs.lionengine.game.feature.Animatable)1 Camera (com.b3dgs.lionengine.game.feature.Camera)1