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