Search in sources :

Example 6 with ViewerMock

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

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

the class CollidableConfigTest method testEmptyAccepted.

/**
 * Test with empty accepted.
 */
@Test
void testEmptyAccepted() {
    final Media media = Medias.create("Object.xml");
    final Xml root = new Xml("test");
    root.save(media);
    final Services services = new Services();
    services.add(new ViewerMock());
    final Collidable collidable = new CollidableModel(services, new Setup(media));
    collidable.setGroup(Integer.valueOf(1));
    CollidableConfig.exports(root, collidable);
    root.save(media);
    final CollidableConfig config = CollidableConfig.imports(new Configurer(media));
    assertEquals(Integer.valueOf(1), config.getGroup());
    assertTrue(config.getAccepted().isEmpty());
    assertTrue(media.getFile().delete());
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) ViewerMock(com.b3dgs.lionengine.ViewerMock) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 8 with ViewerMock

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

the class CollidableConfigTest method testExport.

/**
 * Test export.
 */
@Test
void testExport() {
    final Media media = Medias.create("Object.xml");
    final Xml root = new Xml("test");
    root.save(media);
    final Services services = new Services();
    services.add(new ViewerMock());
    final Collidable collidable = new CollidableModel(services, new Setup(media));
    collidable.setGroup(Integer.valueOf(1));
    collidable.addAccept(Integer.valueOf(2));
    collidable.addAccept(Integer.valueOf(3));
    CollidableConfig.exports(root, collidable);
    root.save(media);
    final CollidableConfig config = CollidableConfig.imports(new Configurer(media));
    assertEquals(Integer.valueOf(1), config.getGroup());
    assertIterableEquals(Arrays.asList(Integer.valueOf(2), Integer.valueOf(3)), config.getAccepted());
    assertTrue(media.getFile().delete());
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) ViewerMock(com.b3dgs.lionengine.ViewerMock) Xml(com.b3dgs.lionengine.Xml) Media(com.b3dgs.lionengine.Media) Setup(com.b3dgs.lionengine.game.feature.Setup) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 9 with ViewerMock

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

the class SpriteAnimatedTest method testSetLocationViewer.

/**
 * Test set location with viewer.
 */
@Test
public void testSetLocationViewer() {
    final SpriteAnimatedImpl sprite = new SpriteAnimatedImpl(Graphics.createImageBuffer(64, 32), 16, 8);
    final ViewerMock viewer = new ViewerMock();
    sprite.setLocation(viewer, Geom.createLocalizable(1.5, 2.5));
    Assert.assertEquals(1.5, sprite.getX(), UtilTests.PRECISION);
    Assert.assertEquals(237.5, sprite.getY(), UtilTests.PRECISION);
    Assert.assertEquals(1, sprite.getRenderX());
    Assert.assertEquals(237, sprite.getRenderY());
    viewer.set(10, 20);
    sprite.setLocation(viewer, Geom.createLocalizable(1.5, 2.5));
    Assert.assertEquals(-8.5, sprite.getX(), UtilTests.PRECISION);
    Assert.assertEquals(257.5, sprite.getY(), UtilTests.PRECISION);
    Assert.assertEquals(-9, sprite.getRenderX());
    Assert.assertEquals(257, sprite.getRenderY());
}
Also used : ViewerMock(com.b3dgs.lionengine.ViewerMock) Test(org.junit.Test)

Example 10 with ViewerMock

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

the class SpriteTest method testSetLocationViewer.

/**
 * Test set location with viewer.
 */
@Test
public void testSetLocationViewer() {
    final SpriteImpl sprite = new SpriteImpl(Graphics.createImageBuffer(64, 32));
    final ViewerMock viewer = new ViewerMock();
    sprite.setLocation(viewer, Geom.createLocalizable(1.5, 2.5));
    Assert.assertEquals(1.5, sprite.getX(), UtilTests.PRECISION);
    Assert.assertEquals(237.5, sprite.getY(), UtilTests.PRECISION);
    Assert.assertEquals(1, sprite.getRenderX());
    Assert.assertEquals(237, sprite.getRenderY());
    viewer.set(10, 20);
    sprite.setLocation(viewer, Geom.createLocalizable(1.5, 2.5));
    Assert.assertEquals(-8.5, sprite.getX(), UtilTests.PRECISION);
    Assert.assertEquals(257.5, sprite.getY(), UtilTests.PRECISION);
    Assert.assertEquals(-9, sprite.getRenderX());
    Assert.assertEquals(257, sprite.getRenderY());
}
Also used : ViewerMock(com.b3dgs.lionengine.ViewerMock) Test(org.junit.Test)

Aggregations

ViewerMock (com.b3dgs.lionengine.ViewerMock)22 Test (org.junit.jupiter.api.Test)13 Test (org.junit.Test)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Media (com.b3dgs.lionengine.Media)3 Camera (com.b3dgs.lionengine.game.feature.Camera)3 ContextMock (com.b3dgs.lionengine.ContextMock)2 Xml (com.b3dgs.lionengine.Xml)2 Configurer (com.b3dgs.lionengine.game.Configurer)2 Cursor (com.b3dgs.lionengine.game.Cursor)2 Featurable (com.b3dgs.lionengine.game.feature.Featurable)2 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)2 Services (com.b3dgs.lionengine.game.feature.Services)2 Setup (com.b3dgs.lionengine.game.feature.Setup)2 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)2 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)2 Animation (com.b3dgs.lionengine.Animation)1 Animatable (com.b3dgs.lionengine.game.feature.Animatable)1 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)1 Factory (com.b3dgs.lionengine.game.feature.Factory)1