Search in sources :

Example 6 with Tile

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

the class MapTileCollisionModel method computeCollision.

/**
 * Compute the collision from current location.
 *
 * @param category The collision category.
 * @param ox The old horizontal location.
 * @param oy The old 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 CollisionResult computeCollision(CollisionCategory category, double ox, double oy, double x, double y) {
    final Tile tile = map.getTile((int) Math.floor(x / map.getTileWidth()), (int) Math.floor(y / map.getTileHeight()));
    if (tile != null) {
        final TileCollision tileCollision = tile.getFeature(TileCollision.class);
        if (containsCollisionFormula(tileCollision, category)) {
            final Double cx = getCollisionX(category, tileCollision, ox, oy, x, y);
            final Double cy = getCollisionY(category, tileCollision, ox, oy, x, y);
            return new CollisionResult(cx, cy, tile);
        }
    }
    return null;
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 7 with Tile

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

the class MapTilePathModel method isBlocked.

// CHECKSTYLE IGNORE LINE: TrailingComment|ReturnCount
@Override
public boolean isBlocked(Pathfindable mover, int tx, int ty, boolean ignoreObjectsId) {
    // Blocked if outside map range
    if (ty >= 0 && tx >= 0 && ty < map.getInTileHeight() && tx < map.getInTileWidth()) {
        // Check if all objects id are non blocking
        if (!ignoreObjectsId) {
            final Collection<Integer> ids = getObjectsId(tx, ty);
            int ignoredCount = 0;
            for (final Integer id : ids) {
                if (// CHECKSTYLE IGNORE LINE: TrailingComment|NestedIfDepth
                mover.isIgnoredId(id)) {
                    ignoredCount++;
                }
            }
            if (// CHECKSTYLE IGNORE LINE: TrailingComment|NestedIfDepth
            ignoredCount < ids.size()) {
                return true;
            }
        }
        // Check if tile is blocking
        final Tile tile = map.getTile(tx, ty);
        if (tile != null) {
            final TilePath tilePath = tile.getFeature(TilePath.class);
            return mover.isBlocking(tilePath.getCategory());
        }
    }
    return true;
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 8 with Tile

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

the class MapTilePathModel method removeObjectId.

@Override
public void removeObjectId(int tx, int ty, Integer id) {
    final Tile tile = map.getTile(tx, ty);
    if (tile != null) {
        final TilePath tilePath = tile.getFeature(TilePath.class);
        tilePath.removeObjectId(id);
    }
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 9 with Tile

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

the class MapTilePathModel method isAreaAvailable.

@Override
public boolean isAreaAvailable(Pathfindable mover, int tx, int ty, int tw, int th, Integer ignoreObjectId) {
    for (int cty = ty; cty < ty + th; cty++) {
        for (int ctx = tx; ctx < tx + tw; ctx++) {
            final Collection<Integer> ids = getObjectsId(ctx, cty);
            final Tile tile = map.getTile(ctx, cty);
            if (tile != null) {
                final TilePath tilePath = tile.getFeature(TilePath.class);
                if (mover.isBlocking(tilePath.getCategory()) || ignoreObjectId != null && !ids.isEmpty() && !ids.contains(ignoreObjectId)) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 10 with Tile

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

the class MapTilePathModel method loadPathfinding.

/*
     * MapTilePath
     */
@Override
public void loadPathfinding(Media pathfindingConfig) {
    final Collection<PathCategory> config = PathfindingConfig.imports(pathfindingConfig);
    categories.clear();
    for (final PathCategory category : config) {
        categories.put(category.getName(), category);
    }
    for (int ty = 0; ty < map.getInTileHeight(); ty++) {
        for (int tx = 0; tx < map.getInTileWidth(); tx++) {
            final Tile tile = map.getTile(tx, ty);
            if (tile != null) {
                final String group = mapGroup.getGroup(tile);
                final String category = getCategory(group);
                final TilePath tilePath = new TilePathModel(category);
                tile.addFeature(tilePath);
            }
        }
    }
}
Also used : 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