Search in sources :

Example 11 with ColorRgba

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

the class MinimapConfig method exports.

/**
 * Export tiles colors data to configuration media.
 *
 * @param configMinimap The configuration media output (must not be <code>null</code>).
 * @param tiles The tiles data (must not be <code>null</code>).
 * @throws LionEngineException If error on writing.
 */
public static void exports(Media configMinimap, Map<Integer, ColorRgba> tiles) {
    Check.notNull(configMinimap);
    Check.notNull(tiles);
    final Map<ColorRgba, Collection<Integer>> colors = convertToColorKey(tiles);
    final Xml nodeMinimap = new Xml(NODE_MINIMAP);
    for (final Map.Entry<ColorRgba, Collection<Integer>> entry : colors.entrySet()) {
        final ColorRgba color = entry.getKey();
        final Xml nodeColor = nodeMinimap.createChild(NODE_COLOR);
        nodeColor.writeInteger(ATT_COLOR_RED, color.getRed());
        nodeColor.writeInteger(ATT_COLOR_GREEN, color.getGreen());
        nodeColor.writeInteger(ATT_COLOR_BLUE, color.getBlue());
        for (final Integer number : entry.getValue()) {
            final Xml nodeTile = TileConfig.exports(number.intValue());
            nodeColor.add(nodeTile);
        }
    }
    nodeMinimap.save(configMinimap);
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) Xml(com.b3dgs.lionengine.Xml) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with ColorRgba

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

the class PathfindableModel method render.

@Override
public void render(Graphic g) {
    if (renderDebug && path != null) {
        final ColorRgba oldColor = g.getColor();
        g.setColor(ColorRgba.GREEN);
        renderPath(g);
        g.setColor(oldColor);
    }
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba)

Example 13 with ColorRgba

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

the class MinimapTest method testMinimap.

/**
 * Test the minimap.
 */
@Test
void testMinimap() {
    final MapTileGame map = new MapTileGame();
    map.loadSheets(Arrays.asList(Drawable.loadSpriteTiled(new ImageBufferMock(80, 80), 40, 40)));
    map.create(40, 40, 3, 3);
    map.setTile(0, 0, 0);
    final Minimap minimap = new Minimap(map);
    final Media config = Medias.create("minimap.xml");
    final Map<Integer, ColorRgba> tiles = new HashMap<>();
    tiles.put(Integer.valueOf(0), ColorRgba.RED);
    tiles.put(Integer.valueOf(1), ColorRgba.BLUE);
    tiles.put(Integer.valueOf(0), ColorRgba.GREEN);
    minimap.automaticColor(config);
    minimap.loadPixelConfig(config);
    minimap.setOrigin(Origin.BOTTOM_LEFT);
    assertEquals(0.0, minimap.getX());
    assertEquals(0.0, minimap.getY());
    assertNull(minimap.getSurface());
    assertFalse(minimap.isLoaded());
    minimap.load();
    minimap.prepare();
    minimap.setLocation(1.0, 2.0);
    minimap.load();
    assertTrue(minimap.isLoaded());
    assertEquals(1.0, minimap.getX());
    assertEquals(-1.0, minimap.getY());
    assertEquals(3, minimap.getWidth());
    assertEquals(3, minimap.getHeight());
    minimap.setLocation(new ViewerMock(), Geom.createLocalizable(2.0, 3.0));
    assertEquals(2.0, minimap.getX());
    assertEquals(234.0, minimap.getY());
    minimap.dispose();
    assertTrue(config.getFile().delete());
}
Also used : ImageBufferMock(com.b3dgs.lionengine.graphic.ImageBufferMock) ViewerMock(com.b3dgs.lionengine.ViewerMock) ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) HashMap(java.util.HashMap) Media(com.b3dgs.lionengine.Media) Test(org.junit.jupiter.api.Test)

Aggregations

ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)13 HashMap (java.util.HashMap)5 ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)3 LionEngineException (com.b3dgs.lionengine.LionEngineException)2 Media (com.b3dgs.lionengine.Media)2 TileRef (com.b3dgs.lionengine.game.feature.tile.TileRef)2 Graphic (com.b3dgs.lionengine.graphic.Graphic)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Test (org.junit.jupiter.api.Test)2 ViewerMock (com.b3dgs.lionengine.ViewerMock)1 Xml (com.b3dgs.lionengine.Xml)1 XmlReader (com.b3dgs.lionengine.XmlReader)1 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)1 ImageBufferMock (com.b3dgs.lionengine.graphic.ImageBufferMock)1 SpriteTiled (com.b3dgs.lionengine.graphic.SpriteTiled)1 SpriteTiled (com.b3dgs.lionengine.graphic.drawable.SpriteTiled)1 Xml (com.b3dgs.lionengine.io.Xml)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1