Search in sources :

Example 1 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 sheet The sheet number.
 */
private void computeSheet(Map<TileRef, ColorRgba> colors, Integer sheet) {
    final SpriteTiled tiles = map.getSheet(sheet);
    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(new TileRef(sheet, number), color);
            }
            number++;
        }
    }
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef)

Example 2 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<TileRef, ColorRgba> tiles) {
    Check.notNull(configMinimap);
    Check.notNull(tiles);
    final Map<ColorRgba, Collection<TileRef>> colors = convertToColorKey(tiles);
    final Xml nodeMinimap = new Xml(NODE_MINIMAP);
    for (final Map.Entry<ColorRgba, Collection<TileRef>> 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 TileRef tileRef : entry.getValue()) {
            final Xml nodeTileRef = TileConfig.exports(tileRef);
            nodeColor.add(nodeTileRef);
        }
    }
    nodeMinimap.save(configMinimap);
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) Xml(com.b3dgs.lionengine.io.Xml) Collection(java.util.Collection) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with ColorRgba

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

the class TextAwt method draw.

@Override
public void draw(Graphic g, int x, int y, Align alignment, String text) {
    final Graphics2D g2d = (Graphics2D) g.getGraphic();
    final FontRenderContext context = g2d.getFontRenderContext();
    final Rectangle2D textSize = font.getStringBounds(text, context);
    final int tx;
    final int ty;
    if (Align.LEFT == alignment) {
        tx = x;
        ty = (int) textSize.getHeight() + y;
    } else if (Align.CENTER == alignment) {
        tx = x - (int) textSize.getWidth() / 2;
        ty = (int) textSize.getHeight() + y;
    } else if (Align.RIGHT == alignment) {
        tx = x - (int) textSize.getWidth();
        ty = (int) textSize.getHeight() + y;
    } else {
        throw new LionEngineException(alignment);
    }
    final ColorRgba colorOld = g.getColor();
    g.setColor(color);
    final GlyphVector glyphVector = font.createGlyphVector(context, text);
    g2d.drawGlyphVector(glyphVector, tx, ty - size / 2.0F);
    g.setColor(colorOld);
}
Also used : GlyphVector(java.awt.font.GlyphVector) ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) LionEngineException(com.b3dgs.lionengine.LionEngineException) Rectangle2D(java.awt.geom.Rectangle2D) FontRenderContext(java.awt.font.FontRenderContext) Graphics2D(java.awt.Graphics2D)

Example 4 with ColorRgba

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

the class TilesExtractor method extract.

/**
 * Extract the tile from level.
 *
 * @param level The level image reference.
 * @param number The tile number on level.
 * @return The extracted tile image from level.
 */
private static ImageBuffer extract(SpriteTiled level, int number) {
    final ColorRgba transparency = level.getSurface().getTransparentColor();
    final ImageBuffer tile = Graphics.createImageBuffer(level.getTileWidth(), level.getTileHeight(), transparency);
    final Graphic g = tile.createGraphic();
    level.setTile(number);
    level.render(g);
    g.dispose();
    final ImageBuffer copy = Graphics.getImageBuffer(tile);
    tile.dispose();
    return copy;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) Graphic(com.b3dgs.lionengine.graphic.Graphic)

Example 5 with ColorRgba

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

the class Minimap method prepare.

/**
 * Fill minimap surface with tile color configuration.
 *
 * @throws LionEngineException If surface has not been loaded ({@link #load()} may have not been called).
 */
@Override
public void prepare() {
    if (surface == null) {
        throw new LionEngineException(ERROR_SURFACE);
    }
    final Graphic g = surface.createGraphic();
    final int v = map.getInTileHeight();
    final int h = map.getInTileWidth();
    for (int ty = 0; ty < v; ty++) {
        for (int tx = 0; tx < h; tx++) {
            final Tile tile = map.getTile(tx, ty);
            final ColorRgba color = getTileColor(tile);
            if (!NO_TILE.equals(color)) {
                g.setColor(color);
                g.drawRect(tx, v - ty - 1, 0, 0, false);
            }
        }
    }
    g.dispose();
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) LionEngineException(com.b3dgs.lionengine.LionEngineException) Graphic(com.b3dgs.lionengine.graphic.Graphic) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

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