Search in sources :

Example 6 with SpriteTiled

use of com.b3dgs.lionengine.graphic.drawable.SpriteTiled in project lionengine by b3dgs.

the class MapTileSurfaceModel method loadSheets.

@Override
public void loadSheets(Media sheetsConfig) {
    this.sheetsConfig = sheetsConfig;
    tilesPerSheet = -1;
    final TileSheetsConfig config = TileSheetsConfig.imports(sheetsConfig);
    final List<String> configSheets = config.getSheets();
    final int sheetsCount = configSheets.size();
    sheets = new SpriteTiled[sheetsCount];
    tileWidth = config.getTileWidth();
    tileHeight = config.getTileHeight();
    for (int sheetId = 0; sheetId < sheetsCount; sheetId++) {
        final String sheetFile = configSheets.get(sheetId);
        final Media sheetMedia = Medias.create(sheetsConfig.getParentPath(), sheetFile);
        final SpriteTiled sheet = Drawable.loadSpriteTiled(sheetMedia, config.getTileWidth(), config.getTileHeight());
        sheet.load();
        sheet.prepare();
        checkTilesPerSheet(sheet);
        checkTileSize(sheet);
        sheets[sheetId] = sheet;
    }
    configSheets.clear();
}
Also used : Media(com.b3dgs.lionengine.Media) SpriteTiled(com.b3dgs.lionengine.graphic.drawable.SpriteTiled)

Example 7 with SpriteTiled

use of com.b3dgs.lionengine.graphic.drawable.SpriteTiled in project lionengine by b3dgs.

the class LevelRipConverter method checkTile.

/**
 * Check tile of sheet.
 *
 * @param map The destination map reference.
 * @param tileSprite The tiled sprite
 * @param sheetId The sheet number.
 * @param x The location x.
 * @param y The location y.
 * @return <code>true</code> if tile found, <code>false</code> else.
 */
private static boolean checkTile(MapTile map, ImageBuffer tileSprite, int sheetId, int x, int y) {
    final int tw = map.getTileWidth();
    final int th = map.getTileHeight();
    final SpriteTiled tileSheet = map.getSheet(sheetId);
    final ImageBuffer sheetImage = tileSheet.getSurface();
    final int tilesInX = tileSheet.getWidth() / tw;
    final int tilesInY = tileSheet.getHeight() / th;
    for (int surfaceCurrentTileY = 0; surfaceCurrentTileY < tilesInY; surfaceCurrentTileY++) {
        for (int surfaceCurrentTileX = 0; surfaceCurrentTileX < tilesInX; surfaceCurrentTileX++) {
            // Tile number on tile sheet
            final int number = surfaceCurrentTileX + surfaceCurrentTileY * tilesInX;
            // Compare tiles between sheet and image map
            final int xa = x * tw;
            final int ya = y * th;
            final int xb = surfaceCurrentTileX * tw;
            final int yb = surfaceCurrentTileY * th;
            if (TilesExtractor.compareTile(tw, th, tileSprite, xa, ya, sheetImage, xb, yb)) {
                map.setTile(x, map.getInTileHeight() - 1 - y, number);
                return true;
            }
        }
    }
    return false;
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) SpriteTiled(com.b3dgs.lionengine.graphic.drawable.SpriteTiled)

Example 8 with SpriteTiled

use of com.b3dgs.lionengine.graphic.drawable.SpriteTiled in project lionengine by b3dgs.

the class MapTileSurfaceModel method loadSheets.

@Override
public void loadSheets(List<SpriteTiled> sheets) {
    final int sheetsCount = sheets.size();
    this.sheets = new SpriteTiled[sheetsCount];
    tilesPerSheet = -1;
    for (int sheetId = 0; sheetId < sheetsCount; sheetId++) {
        final SpriteTiled sheet = sheets.get(sheetId);
        if (tileWidth == 0) {
            tileWidth = sheet.getTileWidth();
            tileHeight = sheet.getTileHeight();
        }
        checkTilesPerSheet(sheet);
        checkTileSize(sheet);
        this.sheets[sheetId] = sheet;
    }
}
Also used : SpriteTiled(com.b3dgs.lionengine.graphic.drawable.SpriteTiled)

Example 9 with SpriteTiled

use of com.b3dgs.lionengine.graphic.drawable.SpriteTiled in project lionengine by b3dgs.

the class MapTileHelper method loadAfter.

/**
 * Load features.
 *
 * @param media The parent media.
 */
public void loadAfter(Media media) {
    if (media != null) {
        final String parent = media.getParentPath();
        final Media configFormulas = Medias.create(parent, CollisionFormulaConfig.FILENAME);
        if (configFormulas.exists()) {
            mapCollision.loadCollisions(configFormulas, Medias.create(parent, CollisionGroupConfig.FILENAME));
        }
        load(media, mapPath::loadPathfinding, PathfindingConfig.FILENAME);
        load(media, mapTransition::loadTransitions, TransitionsConfig.FILENAME);
        load(media, mapCircuit::loadCircuits, CircuitsConfig.FILENAME);
        if (mapRaster.loadSheets()) {
            mapViewer.clear();
            mapViewer.addRenderer(mapRaster);
        }
        final Media configFog = Medias.create(parent, "fog.xml");
        if (configFog.exists()) {
            fogOfWar.create(configFog);
            final int tw = getTileWidth();
            final int th = getTileHeight();
            final SpriteTiled hide = Drawable.loadSpriteTiled(Medias.create(parent, "hide.png"), tw, th);
            final SpriteTiled fog = Drawable.loadSpriteTiled(Medias.create(parent, "fog.png"), tw, th);
            hide.load();
            hide.prepare();
            fog.load();
            fog.prepare();
            fogOfWar.setTilesheet(hide, fog);
            fogOfWar.setEnabled(true, true);
            mapViewer.addRenderer(fogOfWar);
        }
    }
}
Also used : Media(com.b3dgs.lionengine.Media) SpriteTiled(com.b3dgs.lionengine.graphic.drawable.SpriteTiled)

Example 10 with SpriteTiled

use of com.b3dgs.lionengine.graphic.drawable.SpriteTiled in project lionengine by b3dgs.

the class MapTileRasteredModel method renderTile.

@Override
public void renderTile(Graphic g, Tile tile, int x, int y) {
    final SpriteTiled tileRaster = getRasterSheet(tile.getSheetKey(), getRasterIndex(tile.getInTileY()));
    tileRaster.setLocation(x, y);
    tileRaster.setTile(tile.getNumber());
    tileRaster.render(g);
}
Also used : SpriteTiled(com.b3dgs.lionengine.graphic.drawable.SpriteTiled)

Aggregations

SpriteTiled (com.b3dgs.lionengine.graphic.drawable.SpriteTiled)12 ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)5 Media (com.b3dgs.lionengine.Media)3 ArrayList (java.util.ArrayList)2 Surface (com.b3dgs.lionengine.Surface)1 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)1 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)1 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)1 Graphic (com.b3dgs.lionengine.graphic.Graphic)1 RasterImage (com.b3dgs.lionengine.graphic.raster.RasterImage)1 Test (org.junit.jupiter.api.Test)1