Search in sources :

Example 31 with Tile

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

the class MapTileTransitionModel method resolve.

@Override
public Collection<Tile> resolve(Tile tile) {
    final Collection<Tile> resolved = new HashSet<>();
    checkTransitives(resolved, tile);
    final Collection<Tile> toResolve = new ArrayList<>();
    resolve(resolved, toResolve, tile);
    final Collection<Tile> toResolveAfter = new ArrayList<>();
    for (final Tile next : toResolve) {
        resolve(resolved, toResolveAfter, next);
    }
    toResolve.clear();
    toResolveAfter.clear();
    return resolved;
}
Also used : ArrayList(java.util.ArrayList) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) HashSet(java.util.HashSet)

Example 32 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 reference.
 * @param ox The horizontal offset to update.
 * @param oy The vertical offset to update.
 */
private void updateTile(Collection<Tile> resolved, Collection<Tile> toResolve, Tile tile, int ox, int oy) {
    final int tx = tile.getInTileX();
    final int ty = tile.getInTileY();
    final Tile neighbor = map.getTile(tx + ox, ty + oy);
    if (neighbor != null) {
        updateNeigbor(resolved, toResolve, tile, neighbor, ox, oy);
    }
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 33 with Tile

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

the class PathfindableModel method renderPath.

/**
 * Render the current path.
 *
 * @param g The graphic output.
 */
private void renderPath(Graphic g) {
    final int tw = map.getTileWidth();
    final int th = map.getTileHeight();
    for (int i = 0; i < path.getLength(); i++) {
        final int x = (int) viewer.getViewpointX(path.getX(i) * (double) tw);
        final int y = (int) viewer.getViewpointY(path.getY(i) * (double) th);
        g.drawRect(x, y - th, tw, th, true);
        final Tile tile = map.getTile(path.getX(i), path.getY(i));
        if (tile != null) {
            final String category = mapPath.getCategory(tile);
            text.draw(g, x + 2, y - th + 2, String.valueOf(getCost(category)));
        }
    }
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile)

Example 34 with Tile

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

the class MapTileCollisionComputer method computeCollision.

/**
 * Compute the collision from current location.
 *
 * @param map The map surface reference.
 * @param loader The loader reference.
 * @param category The collision category.
 * @param ox The current horizontal location.
 * @param oy The current vertical location.
 * @param x The current horizontal location.
 * @param y The current vertical location.
 * @return The computed collision result, <code>null</code> if none.
 */
private static CollisionResult computeCollision(MapTile map, Function<Tile, List<CollisionFormula>> loader, CollisionCategory category, double ox, double oy, double x, double y) {
    final Tile tile = map.getTileAt(getPositionToSide(ox, x), getPositionToSide(oy, y));
    if (tile != null) {
        Double cx = null;
        Double cy = null;
        CollisionFormula fx = null;
        CollisionFormula fy = null;
        final List<CollisionFormula> formulas = loader.apply(tile);
        for (int i = 0; i < formulas.size(); i++) {
            final CollisionFormula formula = formulas.get(i);
            if (cx == null) {
                cx = getCollisionX(tile, category, formulas, formula, x, y);
                fx = formula;
            }
            if (cy == null) {
                cy = getCollisionY(tile, category, formulas, formula, x, y);
                fy = formula;
            }
            if (cx != null && cy != null) {
                break;
            }
        }
        if (cx != null || cy != null) {
            return new CollisionResult(cx, cy, tile, fx, fy);
        }
    }
    return null;
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 35 with Tile

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

the class CircuitsExtractorImpl method getCircuits.

/**
 * Get map tile circuits.
 *
 * @param map The map reference.
 * @return The circuits found with their associated tiles.
 */
private static Map<Circuit, Collection<Integer>> getCircuits(MapTile map) {
    final MapTileGroup mapGroup = map.getFeature(MapTileGroup.class);
    final Map<Circuit, Collection<Integer>> circuits = new HashMap<>();
    final MapCircuitExtractor extractor = new MapCircuitExtractor(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 && TileGroupType.CIRCUIT == mapGroup.getType(tile)) {
                checkCircuit(circuits, extractor, map, tile);
            }
        }
    }
    return circuits;
}
Also used : MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) 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)

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