Search in sources :

Example 16 with Animation

use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.

the class AnimatableModelTest method testManipulation.

/**
 * Test the manipulations.
 */
@Test
void testManipulation() {
    final int first = 2;
    final int last = 5;
    final double speed = 2.0;
    final Animation animation = new Animation(Animation.DEFAULT_NAME, first, last, speed, false, false);
    final Animatable animatable = new AnimatableModel(services, setup, new AnimatorModel());
    testAnimatorState(animatable, Animation.MINIMUM_FRAME, Animation.MINIMUM_FRAME, AnimState.STOPPED);
    animatable.play(animation);
    testAnimatorState(animatable, first, first, AnimState.PLAYING);
    animatable.setAnimSpeed(speed - 1.0);
    animatable.update(1.0);
    testAnimatorState(animatable, first, first + 1, AnimState.PLAYING);
    animatable.update(1.0);
    animatable.setFrame(1);
    testAnimatorState(animatable, first, 1, AnimState.PLAYING);
    animatable.stop();
    testAnimatorState(animatable, first, 1, AnimState.STOPPED);
}
Also used : Animation(com.b3dgs.lionengine.Animation) AnimatorModel(com.b3dgs.lionengine.AnimatorModel) Test(org.junit.jupiter.api.Test)

Example 17 with Animation

use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.

the class AnimatableModelTest method testPlay.

/**
 * Test the play case.
 */
@Test
void testPlay() {
    final int first = 2;
    final int last = 4;
    final Animation animation = new Animation(Animation.DEFAULT_NAME, first, last, 1.0, false, false);
    final Animatable animatable = new AnimatableModel(services, setup);
    testAnimatorState(animatable, Animation.MINIMUM_FRAME, Animation.MINIMUM_FRAME, AnimState.STOPPED);
    assertEquals(1, animatable.getFrames());
    animatable.play(animation);
    assertEquals(animation, animatable.getAnim());
    testAnimatorState(animatable, first, first, AnimState.PLAYING);
    assertFalse(animatable.is(AnimState.FINISHED));
    assertEquals(last - first + 1, animatable.getFrames());
    animatable.update(1.0);
    testAnimatorState(animatable, first, first + 1, AnimState.PLAYING);
    animatable.update(1.0);
    testAnimatorState(animatable, first, last, AnimState.PLAYING);
    animatable.update(1.0);
    testAnimatorState(animatable, first, last, AnimState.FINISHED);
    animatable.stop();
    testAnimatorState(animatable, first, last, AnimState.STOPPED);
}
Also used : Animation(com.b3dgs.lionengine.Animation) Test(org.junit.jupiter.api.Test)

Example 18 with Animation

use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.

the class AnimationConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    final Xml root = new Xml("test");
    final Animation animation1 = new Animation("anim1", 1, 2, 3.0, false, true);
    final Animation animation2 = new Animation("anim2", 4, 5, 6.0, true, false);
    AnimationConfig.exports(root, animation1);
    AnimationConfig.exports(root, animation2);
    final Media media = Medias.create("animations.xml");
    root.save(media);
    final AnimationConfig imported = AnimationConfig.imports(new Setup(media));
    assertEquals(animation1, imported.getAnimation("anim1"));
    assertEquals(animation2, imported.getAnimation("anim2"));
    assertTrue(imported.getAnimations().containsAll(Arrays.asList(animation1, animation2)));
    assertFalse(imported.hasAnimation("anim"));
    assertTrue(imported.hasAnimation("anim1"));
    assertTrue(imported.hasAnimation("anim2"));
    assertTrue(media.getFile().delete());
}
Also used : Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Animation(com.b3dgs.lionengine.Animation) Setup(com.b3dgs.lionengine.game.feature.Setup) Test(org.junit.jupiter.api.Test)

Example 19 with Animation

use of com.b3dgs.lionengine.Animation 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 20 with Animation

use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.

the class StateHandlerTest method testWithConfig.

/**
 * Test state with configuration.
 */
@Test
void testWithConfig() {
    Medias.setLoadFromJar(StateHandlerTest.class);
    try {
        final Setup setup = new Setup(Medias.create("Object.xml"));
        final Featurable featurable = new FeaturableModel(services, setup);
        final StateHandler handler;
        handler = featurable.addFeatureAndGet(new StateHandler(services, setup));
        handler.prepare(featurable);
        handler.changeState(StateIdle.class);
        handler.postUpdate();
        assertEquals(new Animation(StateIdle.class.getSimpleName(), 1, 1, 0.125, false, false), StateIdle.animation);
        assertNull(StateWalk.animation);
        assertTrue(handler.isState(StateIdle.class));
        handler.update(1.0);
        assertNull(StateWalk.animation);
        handler.postUpdate();
        assertEquals(new Animation(StateWalk.class.getSimpleName(), 2, 2, 0.125, false, false), StateWalk.animation);
        assertTrue(handler.isState(StateWalk.class));
        handler.update(1.0);
        handler.postUpdate();
        assertTrue(handler.isState(StateIdle.class));
    } finally {
        Medias.setLoadFromJar(null);
    }
}
Also used : Animation(com.b3dgs.lionengine.Animation) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Aggregations

Animation (com.b3dgs.lionengine.Animation)41 Test (org.junit.jupiter.api.Test)19 Test (org.junit.Test)13 Animator (com.b3dgs.lionengine.Animator)9 SpriteAnimated (com.b3dgs.lionengine.graphic.SpriteAnimated)6 HashMap (java.util.HashMap)5 Xml (com.b3dgs.lionengine.Xml)4 AnimatorModel (com.b3dgs.lionengine.AnimatorModel)3 Media (com.b3dgs.lionengine.Media)3 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)3 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)3 Collision (com.b3dgs.lionengine.game.feature.collidable.Collision)3 Collection (java.util.Collection)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 AnimState (com.b3dgs.lionengine.AnimState)2 AnimatorListener (com.b3dgs.lionengine.AnimatorListener)2 LionEngineException (com.b3dgs.lionengine.LionEngineException)2 AnimationConfig (com.b3dgs.lionengine.game.AnimationConfig)2 Configurer (com.b3dgs.lionengine.game.Configurer)2 Animatable (com.b3dgs.lionengine.game.feature.Animatable)2