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