Search in sources :

Example 1 with ViewerMock

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

the class SpriteTiledTest method testSetLocationViewer.

/**
 * Test set location with viewer.
 */
@Test
public void testSetLocationViewer() {
    final SpriteTiledImpl sprite = new SpriteTiledImpl(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 2 with ViewerMock

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

the class ImageTest method testSetLocationViewer.

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

Example 3 with ViewerMock

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

the class SpriteFontTest method testSetLocationViewer.

/**
 * Test set location with viewer.
 */
@Test
public void testSetLocationViewer() {
    final SpriteFontImpl sprite = new SpriteFontImpl(media, font, 6, 7);
    sprite.load();
    final ViewerMock viewer = new ViewerMock();
    sprite.setLocation(viewer, Geom.createLocalizable(1.5, 2.5));
    Assert.assertEquals(0.0, sprite.getX(), UtilTests.PRECISION);
    Assert.assertEquals(0.0, sprite.getY(), UtilTests.PRECISION);
    viewer.set(10, 20);
    sprite.setLocation(viewer, Geom.createLocalizable(1.5, 2.5));
    Assert.assertEquals(0.0, sprite.getX(), UtilTests.PRECISION);
    Assert.assertEquals(0.0, sprite.getY(), UtilTests.PRECISION);
}
Also used : ViewerMock(com.b3dgs.lionengine.ViewerMock) Test(org.junit.Test)

Example 4 with ViewerMock

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

the class SpriteAnimatedTest method testSetLocationViewer.

/**
 * Test set location with viewer.
 */
@Test
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));
    assertEquals(1.5, sprite.getX());
    assertEquals(237.5, sprite.getY());
    assertEquals(2, sprite.getRenderX());
    assertEquals(238, sprite.getRenderY());
    viewer.set(10, 20);
    sprite.setLocation(viewer, Geom.createLocalizable(1.5, 2.5));
    assertEquals(-8.5, sprite.getX());
    assertEquals(257.5, sprite.getY());
    assertEquals(-8, sprite.getRenderX());
    assertEquals(258, sprite.getRenderY());
}
Also used : ViewerMock(com.b3dgs.lionengine.ViewerMock) Test(org.junit.jupiter.api.Test)

Example 5 with ViewerMock

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

the class GraphicTest method testGraphic.

/**
 * Test graphic.
 */
@Test
protected void testGraphic() {
    final ImageBuffer image = Graphics.createImageBuffer(320, 240);
    final Graphic g = image.createGraphic();
    assertNotNull(g.getGraphic());
    g.clear(0, 0, image.getWidth(), image.getHeight());
    g.copyArea(0, 0, image.getWidth(), image.getHeight(), 0, 0);
    g.drawImage(image, 0, 0);
    final Transform transform = Graphics.createTransform();
    g.drawImage(image, transform, 0, 0);
    g.drawImage(image, transform, 0, 0);
    g.drawImage(image, 0, 0, 0, 0, 0, 0, 0, 0);
    g.drawImage(image, 0, 0, 0, 0, 2, 0, 0, 0);
    g.drawImage(image, 0, 0, 0, 0, 2, 0, 0, 0);
    g.drawImage(image, 0, 0, 0, 0, 2, 0, 0, 0, 0, 20, 30);
    g.drawImage(image, 0, 0, 0, 0, 2, 0, 0, 0, 10, 20, 30);
    g.drawLine(0, 0, 0, 0);
    g.drawOval(0, 0, image.getWidth(), image.getHeight(), true);
    g.drawOval(0, 0, image.getWidth(), image.getHeight(), false);
    g.drawRect(0, 0, 1, 0, true);
    g.drawRect(0, 0, 0, 1, true);
    g.drawRect(0, 0, 0, 0, true);
    g.drawRect(0, 0, image.getWidth(), image.getHeight(), true);
    g.drawRect(0, 0, image.getWidth(), image.getHeight(), false);
    assertEquals(ColorRgba.WHITE.getRgba(), g.getColor().getRgba());
    g.setColor(ColorRgba.BLUE);
    g.setColor(ColorRgba.BLUE);
    assertEquals(ColorRgba.BLUE.getRgba(), g.getColor().getRgba());
    g.setColorGradient(new ColorGradient(0, 0, ColorRgba.CYAN, 100, 100, ColorRgba.RED));
    g.setColorGradient(new ColorGradient(0, 0, ColorRgba.CYAN, 100, 100, ColorRgba.RED));
    g.drawGradient(0, 0, 100, 100);
    g.drawLine(new ViewerMock(), 1, 2, 3, 4);
    g.drawLine(new ViewerMock(), 1, 3, 2, 4);
    g.drawLine(new ViewerMock(), 1, 2, 2, 1);
    g.drawLine(new ViewerMock(), 4, 3, 2, 3);
    g.drawOval(new ViewerMock(), Origin.BOTTOM_LEFT, 0, 0, image.getWidth(), image.getHeight(), true);
    g.drawRect(new ViewerMock(), Origin.BOTTOM_LEFT, 0, 0, image.getWidth(), image.getHeight(), true);
    g.drawRect(new ViewerMock(), Origin.BOTTOM_LEFT, Geom.createArea(0, 0, image.getWidth(), image.getHeight()), true);
    g.drawGradient(new ViewerMock(), Origin.BOTTOM_LEFT, 0, 0, 100, 100);
    g.dispose();
    g.setGraphic(null);
    assertNull(g.getGraphic());
    image.dispose();
}
Also used : ViewerMock(com.b3dgs.lionengine.ViewerMock) Test(org.junit.jupiter.api.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