Search in sources :

Example 11 with Graphic

use of com.b3dgs.lionengine.graphic.Graphic in project lionengine by b3dgs.

the class ParallaxTest method testParallax.

/**
 * Test clouds.
 */
@Test
void testParallax() {
    final Parallax parallax = new Parallax(new SourceResolutionProvider() {

        @Override
        public int getWidth() {
            return 320;
        }

        @Override
        public int getHeight() {
            return 240;
        }

        @Override
        public int getRate() {
            return 60;
        }
    }, Medias.create("surface.png"), 11, 1, 2, 100, 100);
    parallax.setScreenSize(320, 240);
    parallax.update(1.0, 1, 0, 200.0);
    parallax.update(1.0, 1, 200, 200.0);
    parallax.update(1.0, 1, 300, 200.0);
    parallax.update(1.0, 1, 0, -200.0);
    parallax.update(1.0, 1, 0, -200.0);
    parallax.update(1.0, 1, 0, -200.0);
    final Graphic g = Graphics.createGraphic();
    parallax.render(g);
    g.dispose();
}
Also used : Graphic(com.b3dgs.lionengine.graphic.Graphic) SourceResolutionProvider(com.b3dgs.lionengine.graphic.engine.SourceResolutionProvider) Test(org.junit.jupiter.api.Test)

Example 12 with Graphic

use of com.b3dgs.lionengine.graphic.Graphic in project lionengine by b3dgs.

the class CloudsTest method testClouds.

/**
 * Test clouds.
 */
@Test
void testClouds() {
    final CloudsAbstract clouds = new CloudsAbstract(Medias.create("surface.png"), 7, 1, 10, 0) {
    };
    clouds.setY(0, 1);
    clouds.setScreenWidth(20);
    clouds.setSpeed(0, 2);
    clouds.update(1.0, 1, 2, 3.0);
    final Graphic g = Graphics.createGraphic();
    clouds.render(g);
    g.dispose();
}
Also used : Graphic(com.b3dgs.lionengine.graphic.Graphic) Test(org.junit.jupiter.api.Test)

Example 13 with Graphic

use of com.b3dgs.lionengine.graphic.Graphic in project lionengine by b3dgs.

the class BarTest method testBar.

/**
 * Test the bar class.
 */
@Test
void testBar() {
    final Graphic g = new GraphicMock();
    final Bar bar = new Bar(10, 20);
    bar.setBorderSize(1, 1);
    bar.setColorBackground(ColorRgba.WHITE);
    bar.setColorForeground(ColorRgba.BLACK);
    bar.setLocation(0, 0);
    bar.setMaximumSize(10, 20);
    bar.setVerticalReferential(true);
    bar.setHorizontalReferential(true);
    bar.setWidthPercent(100);
    bar.setHeightPercent(100);
    assertEquals(10, bar.getWidthMax());
    assertEquals(20, bar.getHeightMax());
    assertEquals(100, bar.getWidthPercent());
    assertEquals(100, bar.getHeightPercent());
    assertEquals(10, bar.getWidth());
    assertEquals(20, bar.getHeight());
    bar.setWidthPercent(50);
    bar.setHeightPercent(50);
    assertEquals(50, bar.getWidthPercent());
    assertEquals(50, bar.getHeightPercent());
    assertEquals(5, bar.getWidth());
    assertEquals(10, bar.getHeight());
    bar.render(g);
    bar.setColorBackground(null);
    bar.setVerticalReferential(false);
    bar.setHorizontalReferential(true);
    bar.render(g);
    bar.setColorBackground(ColorRgba.WHITE);
    bar.setColorForeground(null);
    bar.setVerticalReferential(false);
    bar.setHorizontalReferential(false);
    bar.render(g);
    bar.setColor(null, null);
    bar.setVerticalReferential(true);
    bar.setHorizontalReferential(false);
    bar.render(g);
    bar.setWidthPercent(100);
    bar.setHeightPercent(0);
    bar.render(g);
    bar.setWidthPercent(0);
    bar.setHeightPercent(100);
    bar.render(g);
    bar.setWidthPercent(100);
    bar.setHeightPercent(100);
    bar.setColorGradient(0, 0, ColorRgba.WHITE, 50, 10, ColorRgba.BLACK);
    bar.render(g);
    bar.setColorGradient(ColorRgba.WHITE, ColorRgba.BLACK);
    bar.render(g);
}
Also used : GraphicMock(com.b3dgs.lionengine.graphic.GraphicMock) Graphic(com.b3dgs.lionengine.graphic.Graphic) Test(org.junit.jupiter.api.Test)

Example 14 with Graphic

use of com.b3dgs.lionengine.graphic.Graphic in project lionengine by b3dgs.

the class TimedMessageTest method testRender.

/**
 * Test render.
 */
@Test
void testRender() {
    final TimedMessage message = new TimedMessage(Graphics.createText(Constant.FONT_DIALOG, 8, TextStyle.NORMAL));
    message.addMessage("test", 0, 0, 0L);
    final Graphic g = Graphics.createGraphic();
    message.render(g);
    message.update(1.0);
    message.render(g);
    g.dispose();
    assertFalse(message.hasMessage());
}
Also used : Graphic(com.b3dgs.lionengine.graphic.Graphic) Test(org.junit.jupiter.api.Test)

Example 15 with Graphic

use of com.b3dgs.lionengine.graphic.Graphic in project lionengine by b3dgs.

the class TextGameTest method testDraw.

/**
 * Test draw.
 */
@Test
void testDraw() {
    final Graphic g = new GraphicMock();
    final TextGame text = new TextGame(Constant.FONT_DIALOG, 8, TextStyle.NORMAL);
    text.setText("text");
    text.setAlign(Align.CENTER);
    text.setColor(ColorRgba.WHITE);
    text.render(g);
    text.draw(g, 0, 0, "toto");
    text.draw(g, 1, 2, Align.LEFT, "tata");
    text.draw(g, Geom.createLocalizable(3, 4), 1, 2, Align.RIGHT, "titi");
    text.drawRect(g, ColorRgba.BLACK, 0, 0, 10, 20);
    g.dispose();
}
Also used : GraphicMock(com.b3dgs.lionengine.graphic.GraphicMock) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) Graphic(com.b3dgs.lionengine.graphic.Graphic) Test(org.junit.jupiter.api.Test)

Aggregations

Graphic (com.b3dgs.lionengine.graphic.Graphic)45 Test (org.junit.jupiter.api.Test)18 ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)12 FactoryGraphic (com.b3dgs.lionengine.graphic.FactoryGraphic)9 Test (org.junit.Test)8 BufferedImage (java.awt.image.BufferedImage)5 GraphicMock (com.b3dgs.lionengine.graphic.GraphicMock)4 LionEngineException (com.b3dgs.lionengine.LionEngineException)3 Resolution (com.b3dgs.lionengine.Resolution)3 FactoryGraphicMock (com.b3dgs.lionengine.graphic.FactoryGraphicMock)3 Media (com.b3dgs.lionengine.Media)2 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)2 SpriteFont (com.b3dgs.lionengine.graphic.SpriteFont)2 Text (com.b3dgs.lionengine.graphic.Text)2 Align (com.b3dgs.lionengine.Align)1 Surface (com.b3dgs.lionengine.Surface)1 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)1 Image (com.b3dgs.lionengine.graphic.Image)1 Sprite (com.b3dgs.lionengine.graphic.Sprite)1 SpriteAnimated (com.b3dgs.lionengine.graphic.SpriteAnimated)1