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;
}
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);
}
}
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)));
}
}
}
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;
}
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;
}
Aggregations