Search in sources :

Example 6 with ColorRgba

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

the class GraphicAwt method getColor.

@Override
public ColorRgba getColor() {
    final Color color = g.getColor();
    if (colorCacheAwt.containsKey(color)) {
        return colorCacheAwt.get(color);
    }
    final ColorRgba colorRgba = new ColorRgba(color.getRGB());
    colorCacheAwt.put(color, colorRgba);
    return colorRgba;
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) Color(java.awt.Color)

Example 7 with ColorRgba

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

the class MinimapConfigTest method testExportsImports.

/**
 * Test exports imports.
 */
@Test
void testExportsImports() {
    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);
    tiles.put(Integer.valueOf(1), ColorRgba.GREEN);
    final Media config = Medias.create("minimap.xml");
    MinimapConfig.exports(config, tiles);
    assertEquals(tiles, MinimapConfig.imports(config));
    assertTrue(config.getFile().delete());
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) HashMap(java.util.HashMap) Media(com.b3dgs.lionengine.Media) Test(org.junit.jupiter.api.Test)

Example 8 with ColorRgba

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

the class ScanlineCrt method createColor.

private static ColorRgba[][] createColor() {
    final int f = 14;
    final ColorRgba[][] color = new ColorRgba[][] { { new ColorRgba(5 * f / 3, 1 * f / 4, 1 * f / 3, (int) (ALPHA * 0.9)), new ColorRgba(1 * f / 3, 5 * f / 4, 1 * f / 3, (int) (ALPHA * 0.9)), new ColorRgba(1 * f / 3, 1 * f / 4, 5 * f / 3, (int) (ALPHA * 0.9)) }, { new ColorRgba(10 * f / 2, 2 * f / 2, 2 * f / 2, (int) (ALPHA * 0.75)), new ColorRgba(2 * f / 2, 10 * f / 2, 2 * f / 2, (int) (ALPHA * 0.75)), new ColorRgba(2 * f / 2, 2 * f / 2, 10 * f / 2, (int) (ALPHA * 0.75)) }, { new ColorRgba(18 * f, 4 * f, 4 * f, (int) (ALPHA * 0.5)), new ColorRgba(4 * f, 18 * f, 4 * f, (int) (ALPHA * 0.5)), new ColorRgba(4 * f, 4 * f, 18 * f, (int) (ALPHA * 0.5)) }, { new ColorRgba(12 * f, 3 * f, 3 * f, (int) (ALPHA * 0.6)), new ColorRgba(3 * f, 12 * f, 3 * f, (int) (ALPHA * 0.6)), new ColorRgba(3 * f, 3 * f, 12 * f, (int) (ALPHA * 0.6)) }, { new ColorRgba(8 * f / 2, 5 * f / 2, 2 * f / 2, (int) (ALPHA * 0.8)), new ColorRgba(2 * f / 2, 8 * f / 2, 2 * f / 2, (int) (ALPHA * 0.8)), new ColorRgba(2 * f / 2, 2 * f / 2, 8 * f / 2, (int) (ALPHA * 0.8)) } };
    return color;
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba)

Example 9 with ColorRgba

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

the class Minimap method computeSheet.

/**
 * Compute the current sheet.
 *
 * @param colors The colors data.
 * @param sheetId The sheet id.
 */
private void computeSheet(Map<Integer, ColorRgba> colors, int sheetId) {
    final SpriteTiled tiles = map.getSheet(sheetId);
    final ImageBuffer tilesSurface = tiles.getSurface();
    final int tw = map.getTileWidth();
    final int th = map.getTileHeight();
    int number = 0;
    for (int i = 0; i < tilesSurface.getWidth(); i += tw) {
        for (int j = 0; j < tilesSurface.getHeight(); j += th) {
            final int h = number * tw % tiles.getWidth();
            final int v = number / tiles.getTilesHorizontal() * th;
            final ColorRgba color = UtilColor.getWeightedColor(tilesSurface, h, v, tw, th);
            if (!(NO_TILE.equals(color) || color.getAlpha() == 0)) {
                colors.put(Integer.valueOf(number), color);
            }
            number++;
        }
    }
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) SpriteTiled(com.b3dgs.lionengine.graphic.drawable.SpriteTiled)

Example 10 with ColorRgba

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

the class MinimapConfig method imports.

/**
 * Create the minimap data from node.
 *
 * @param configMinimap The minimap configuration media (must not be <code>null</code>).
 * @return The minimap data.
 * @throws LionEngineException If unable to read data.
 */
public static Map<Integer, ColorRgba> imports(Media configMinimap) {
    Check.notNull(configMinimap);
    final Map<Integer, ColorRgba> colors = new HashMap<>();
    final XmlReader nodeMinimap = new XmlReader(configMinimap);
    final Collection<XmlReader> children = nodeMinimap.getChildren(NODE_COLOR);
    for (final XmlReader nodeColor : children) {
        final ColorRgba color = new ColorRgba(nodeColor.getInteger(ATT_COLOR_RED), nodeColor.getInteger(ATT_COLOR_GREEN), nodeColor.getInteger(ATT_COLOR_BLUE));
        for (final XmlReader nodeTile : nodeColor.getChildren(TileConfig.NODE_TILE)) {
            final Integer tile = Integer.valueOf(TileConfig.imports(nodeTile));
            colors.put(tile, color);
        }
    }
    children.clear();
    return colors;
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) HashMap(java.util.HashMap) XmlReader(com.b3dgs.lionengine.XmlReader)

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