use of com.b3dgs.lionengine.game.feature.tile.TileGame 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.TileGame 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.TileGame in project lionengine by b3dgs.
the class CollisionResultTest method testNoResult.
/**
* Test the collision no result.
*/
@Test
void testNoResult() {
final Tile tile = new TileGame(1, 3, 4, 1, 1);
CollisionResult result = new CollisionResult(null, null, tile, null, null);
assertFalse(result.startWithX("formula"));
assertFalse(result.startWithY("formulaZ"));
assertFalse(result.contains("formula"));
result = new CollisionResult(null, null, tile, formulaX, null);
assertTrue(result.startWithX("formula"));
assertFalse(result.startWithX("formulaZ"));
assertFalse(result.startWithY("formula"));
assertFalse(result.startWithY("formulaZ"));
assertTrue(result.contains("formula"));
assertFalse(result.contains("formulaZ"));
result = new CollisionResult(null, null, tile, null, formulaY);
assertFalse(result.startWithX("formula"));
assertFalse(result.startWithX("formulaZ"));
assertTrue(result.startWithY("formula"));
assertFalse(result.startWithY("formulaZ"));
assertTrue(result.contains("formula"));
assertFalse(result.contains("formulaZ"));
}
Aggregations