Search in sources :

Example 51 with Tile

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

the class MapTileTransitionModel method checkTransitives.

/**
 * Check tile transitive groups.
 *
 * @param resolved The resolved tiles.
 * @param tile The tile to check.
 */
private void checkTransitives(Collection<Tile> resolved, Tile tile) {
    boolean isTransitive = false;
    final Integer old = tile.getKey();
    for (final Tile neighbor : map.getNeighbors(tile)) {
        final String group = mapGroup.getGroup(old);
        final String neighborGroup = mapGroup.getGroup(neighbor);
        final Collection<GroupTransition> transitives = getTransitives(group, neighborGroup);
        if (transitives.size() > 1 && (getTransition(neighbor, group) == null || isCenter(neighbor))) {
            final int iterations = transitives.size() - 3;
            int i = 0;
            for (final GroupTransition transitive : transitives) {
                updateTransitive(resolved, tile, neighbor, transitive);
                isTransitive = true;
                i++;
                if (i > iterations) {
                    break;
                }
            }
        }
    }
    // Restore initial tile once transition solved by transitive
    if (isTransitive) {
        map.setTile(tile.getInTileX(), tile.getInTileY(), old.intValue());
    }
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 52 with Tile

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

the class MapTileTransitionModel method updateTransitive.

/**
 * Update the transitive between tile and its neighbor.
 *
 * @param resolved The resolved tiles.
 * @param tile The tile reference.
 * @param neighbor The neighbor reference.
 * @param transitive The transitive involved.
 */
private void updateTransitive(Collection<Tile> resolved, Tile tile, Tile neighbor, GroupTransition transitive) {
    final String transitiveOut = transitive.getOut();
    final Transition transition = new Transition(TransitionType.CENTER, transitiveOut, transitiveOut);
    final Collection<Integer> refs = getTiles(transition);
    if (!refs.isEmpty()) {
        final Integer ref = refs.iterator().next();
        // Replace user tile with the needed tile to solve transition (restored later)
        map.setTile(tile.getInTileX(), tile.getInTileY(), ref.intValue());
        // Replace neighbor with the needed tile to solve transition
        final Tile newTile2 = new TileGame(ref.intValue(), neighbor.getInTileX(), neighbor.getInTileY(), neighbor.getWidth(), neighbor.getHeight());
        map.setTile(newTile2.getInTileX(), newTile2.getInTileY(), newTile2.getNumber());
        resolved.addAll(resolve(newTile2));
    }
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile) TileGame(com.b3dgs.lionengine.game.feature.tile.TileGame)

Example 53 with Tile

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

the class MapTileTransitionModel method updateTile.

/**
 * Update tile.
 *
 * @param resolved The resolved tiles.
 * @param toResolve Tiles to resolve after.
 * @param tile The tile placed.
 * @param neighbor The tile to update.
 * @param transition The transition to set.
 */
private void updateTile(Collection<Tile> resolved, Collection<Tile> toResolve, Tile tile, Tile neighbor, Transition transition) {
    final Iterator<Integer> iterator = getTiles(transition).iterator();
    if (iterator.hasNext()) {
        final Integer ref = iterator.next();
        map.setTile(neighbor.getInTileX(), neighbor.getInTileY(), ref.intValue());
        resolved.add(new TileGame(ref.intValue(), neighbor.getInTileX(), neighbor.getInTileY(), map.getTileWidth(), map.getTileHeight()));
    } else {
        final Tile newTile = new TileGame(tile.getNumber(), neighbor.getInTileX(), neighbor.getInTileY(), tile.getWidth(), tile.getHeight());
        final String groupA = mapGroup.getGroup(tile);
        final String groupB = mapGroup.getGroup(neighbor);
        // Used to fix transitions not found
        if (!neighbor.equals(newTile) && (!isCenter(neighbor) || groupA.equals(groupB) || groupLinks.contains(new GroupTransition(groupA, groupB)))) {
            map.setTile(newTile.getInTileX(), newTile.getInTileY(), newTile.getNumber());
            toResolve.add(newTile);
        }
        resolved.add(newTile);
    }
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile) TileGame(com.b3dgs.lionengine.game.feature.tile.TileGame)

Example 54 with Tile

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

the class TransitionsExtractorImpl method getTransitions.

/**
 * Get map tile transitions.
 *
 * @param map The map reference.
 * @return The transitions found with their associated tiles.
 */
private static Map<Transition, Collection<Integer>> getTransitions(MapTile map) {
    final Map<Transition, Collection<Integer>> transitions = new HashMap<>();
    final MapTransitionExtractor extractor = new MapTransitionExtractor(map);
    for (int ty = 1; ty < map.getInTileHeight() - 1; ty++) {
        for (int tx = 1; tx < map.getInTileWidth() - 1; tx++) {
            final Tile tile = map.getTile(tx, ty);
            if (tile != null) {
                checkTransition(transitions, extractor, tile);
            }
        }
    }
    return transitions;
}
Also used : HashMap(java.util.HashMap) Collection(java.util.Collection) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 55 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, 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 : 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