Search in sources :

Example 1 with Tile

use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.

the class PrefMapFill method apply.

/*
     * Preference
     */
@Override
public void apply(MapTile map) {
    final double tw = map.getTileWidth();
    final double th = map.getTileHeight();
    for (int tx = 0; tx < map.getInTileWidth(); tx++) {
        final double x = tx * tw;
        for (int ty = 0; ty < map.getInTileHeight(); ty++) {
            final double y = ty * th;
            final Tile tile = map.createTile(sheet, number, x, y);
            map.setTile(tile);
        }
    }
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 2 with Tile

use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.

the class FogOfWar method renderTile.

/*
     * MapTileRenderer
     */
@Override
public void renderTile(Graphic g, MapTile map, Tile tile, int x, int y) {
    final int tx = tile.getInTileX();
    final int ty = tile.getInTileY();
    final Tile fogTile = mapFogged.getTile(tx, ty);
    if (fogMap && fogTile != null && fogTile.getNumber() != MapTileFog.NO_FOG) {
        fogTiles.setLocation(x, y);
        fogTiles.setTile(fogTile.getNumber());
        fogTiles.render(g);
    }
    final Tile hideTile = mapHidden.getTile(tx, ty);
    if (hideMap && hideTile != null && hideTile.getNumber() != MapTileFog.NO_FOG) {
        hideTiles.setTile(hideTile.getNumber());
        hideTiles.setLocation(x, y);
        hideTiles.render(g);
    }
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 3 with Tile

use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.

the class MapTileFog method updateFov.

/**
 * Update fovable field of view (fog of war).
 *
 * @param fovable The fovable reference.
 */
private void updateFov(Fovable fovable) {
    final int tx = fovable.getInTileX();
    final int ty = fovable.getInTileY();
    final int tw = fovable.getInTileWidth();
    final int th = fovable.getInTileHeight();
    final int ray = fovable.getInTileFov();
    final int sx = UtilMath.clamp(tx - ray - tw / 2, 0, map.getInTileWidth() - 1);
    final int ex = UtilMath.clamp(tx + ray + tw / 2, 0, map.getInTileWidth() - 1);
    final int sy = UtilMath.clamp(ty - ray - th / 2, 0, map.getInTileHeight() - 1);
    final int ey = UtilMath.clamp(ty + ray + th / 2, 0, map.getInTileHeight() - 1);
    for (int x = sx + 1; x < ex; x++) {
        for (int y = sy + 1; y < ey; y++) {
            final Tile tile = new TileGame(Integer.valueOf(0), NO_FOG, x * map.getTileWidth(), y * map.getTileHeight(), map.getTileWidth(), map.getTileHeight());
            map.setTile(tile);
            transition.resolve(getTile(x, y));
        }
    }
    for (int x = sx; x < ex + 1; x++) {
        for (int y = sy; y < ey + 1; y++) {
            final Tile tile = map.getTile(x, y);
            revealed.add(tile);
        }
    }
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) TileGame(com.b3dgs.lionengine.game.feature.tile.TileGame)

Example 4 with Tile

use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.

the class LevelRipConverter method checkPixel.

/**
 * Check the pixel by searching tile on sheet.
 *
 * @param map The destination map reference.
 * @param tileRef The tile sheet.
 * @param progressTileX The progress on horizontal tiles.
 * @param progressTileY The progress on vertical tiles.
 * @return <code>true</code> if tile found, <code>false</code> else.
 */
private static boolean checkPixel(MapTile map, ImageBuffer tileRef, int progressTileX, int progressTileY) {
    final int x = progressTileX * map.getTileWidth();
    final int y = progressTileY * map.getTileHeight();
    final int pixel = tileRef.getRgb(x, y);
    // Skip blank tile of image map
    if (TilesExtractor.IGNORED_COLOR_VALUE != pixel) {
        // Search if tile is on sheet and get it
        final Tile tile = searchForTile(map, tileRef, progressTileX, progressTileY);
        if (tile == null) {
            return false;
        }
        map.setTile(tile);
    }
    return true;
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 5 with Tile

use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.

the class MapTileGame method appendMap.

/**
 * Append the map at specified offset.
 *
 * @param map The map to append.
 * @param offsetX The horizontal offset.
 * @param offsetY The vertical offset.
 */
private void appendMap(MapTile map, int offsetX, int offsetY) {
    for (int v = 0; v < map.getInTileHeight(); v++) {
        final int ty = offsetY + v;
        for (int h = 0; h < map.getInTileWidth(); h++) {
            final int tx = offsetX + h;
            final Tile tile = map.getTile(h, v);
            if (tile != null) {
                final double x = tx * (double) tileWidth;
                final double y = ty * (double) tileHeight;
                setTile(createTile(tile.getSheet(), tile.getNumber(), x, y));
            }
        }
    }
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Aggregations

Tile (com.b3dgs.lionengine.game.feature.tile.Tile)59 MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)26 Test (org.junit.jupiter.api.Test)13 TileGame (com.b3dgs.lionengine.game.feature.tile.TileGame)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 Transformable (com.b3dgs.lionengine.game.feature.Transformable)7 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)6 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 MapTileGroup (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 LionEngineException (com.b3dgs.lionengine.LionEngineException)2 Media (com.b3dgs.lionengine.Media)2 Force (com.b3dgs.lionengine.game.Force)2 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)2 MapTileTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition)2 SpriteTiled (com.b3dgs.lionengine.graphic.SpriteTiled)2 GroupTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.GroupTransition)1