use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.
the class MapTilePathModel method isTileNotAvailable.
/**
* Check if area if used.
*
* @param mover The object moving on map.
* @param ctx The horizontal tile index.
* @param cty The vertical tile index.
* @param ignoreObjectId The object ID to ignore.
* @return <code>true</code> if area is used, <code>false</code> else.
*/
private boolean isTileNotAvailable(Pathfindable mover, int ctx, int cty, Integer ignoreObjectId) {
final Collection<Integer> ids = getObjectsId(ctx, cty);
final Tile tile = map.getTile(ctx, cty);
if (tile != null) {
final String category = getCategory(tile);
return mover.isBlocking(category) || !ids.isEmpty() && (ignoreObjectId == null || !ids.contains(ignoreObjectId));
}
return true;
}
use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.
the class MapTileCollisionLoader method checkConstraints.
/**
* Check the tile constraints and get the removable formulas.
*
* @param map The map surface reference.
* @param mapGroup The map group reference.
* @param tile The current tile to check.
* @param h The horizontal location.
* @param v The vertical location.
* @return The formula to remove.
*/
private Collection<CollisionFormula> checkConstraints(MapTile map, MapTileGroup mapGroup, Tile tile, int h, int v) {
final Tile top = map.getTile(h, v + 1);
final Tile bottom = map.getTile(h, v - 1);
final Tile left = map.getTile(h - 1, v);
final Tile right = map.getTile(h + 1, v);
final List<CollisionFormula> toRemove = new ArrayList<>();
for (final CollisionFormula formula : tilesFormulas.computeIfAbsent(tile, t -> Collections.emptyList())) {
final CollisionConstraint constraint = formula.getConstraint();
if (checkConstraint(mapGroup, constraint.getConstraints(Orientation.NORTH), top) || checkConstraint(mapGroup, constraint.getConstraints(Orientation.SOUTH), bottom) || checkConstraint(mapGroup, constraint.getConstraints(Orientation.WEST), left) || checkConstraint(mapGroup, constraint.getConstraints(Orientation.EAST), right)) {
toRemove.add(formula);
}
}
return toRemove;
}
use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.
the class MapTilePersisterModelTest method testSaveLoad.
/**
* Test the save and load map from file.
*
* @throws IOException If error.
*/
@Test
void testSaveLoad() throws IOException {
final MapTile map = UtilMapTilePersister.createMap();
assertEquals(map.getInTileWidth() * (map.getInTileHeight() - 1), map.getTilesNumber());
final Media level = Medias.create("level");
UtilMapTilePersister.saveMap(map, level);
final MapTile mapLoaded = UtilMapTilePersister.loadMap(level);
assertEquals(map.getTileWidth(), mapLoaded.getTileWidth());
assertEquals(map.getTileHeight(), mapLoaded.getTileHeight());
assertEquals(map.getInTileWidth(), mapLoaded.getInTileWidth());
assertEquals(map.getInTileHeight(), mapLoaded.getInTileHeight());
assertEquals(map.getWidth(), mapLoaded.getWidth());
assertEquals(map.getHeight(), mapLoaded.getHeight());
for (int x = 0; x < mapLoaded.getInTileWidth(); x++) {
for (int y = 0; y < mapLoaded.getInTileHeight(); y++) {
final Tile tile = mapLoaded.getTile(x, y);
if (y == 0) {
assertNull(tile);
} else {
assertNotNull(tile);
assertEquals(x * y, tile.getNumber());
assertEquals(x * mapLoaded.getTileWidth(), tile.getX());
assertEquals(y * mapLoaded.getTileHeight(), tile.getY());
}
}
}
assertEquals(map.getTilesNumber(), mapLoaded.getTilesNumber());
assertTrue(level.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.
the class MapTileTransitionModelTest method testResolution.
/**
* Test the map resolution.
*
* @param tileNumber The initial tile number.
* @param groupOrigin The initial group.
* @param tileNew The new tile number.
* @param groupNew The new tile group.
* @param transition The transition between initial tile and new tile.
*/
private static void testResolution(int tileNumber, String groupOrigin, int tileNew, String groupNew, String transition) {
final MapTile map = UtilMap.createMap(12);
UtilMap.fill(map, tileNumber);
map.getFeature(MapTileTransition.class).loadTransitions(config);
final MapTileGroup mapGroup = map.getFeature(MapTileGroup.class);
final MapTileTransition mapTransition = map.getFeature(MapTileTransitionModel.class);
assertEquals(groupOrigin, mapGroup.getGroup(map.getTile(8, 8)));
map.setTile(8, 8, tileNew);
final Tile tile = map.getTile(8, 8);
assertEquals(groupNew, mapGroup.getGroup(map.getTile(8, 8)));
for (final Tile neighbor : map.getNeighbors(tile)) {
assertEquals(groupOrigin, mapGroup.getGroup(neighbor));
}
mapTransition.resolve(tile);
for (final Tile neighbor : map.getNeighbors(tile)) {
assertEquals(transition, mapGroup.getGroup(neighbor));
}
}
use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.
the class TransitiveGroupTest method testTransitives.
/**
* Test the transitive groups.
*/
@Test
void testTransitives() {
final MapTile map = UtilMap.createMap(30);
UtilMap.fill(map, TILE_WATER);
final Media config = UtilMapTransition.createTransitions();
final MapTileGroup mapGroup = map.getFeature(MapTileGroup.class);
map.getFeature(MapTileTransition.class).loadTransitions(config);
final TransitiveGroup transitive = new TransitiveGroup(map);
transitive.load();
assertEquals(Arrays.asList(new GroupTransition(WATER, GROUND), new GroupTransition(GROUND, TREE)), transitive.getTransitives(WATER, TREE));
assertEquals(WATER, mapGroup.getGroup(map.getTile(15, 15)));
map.setTile(15, 15, TILE_TREE);
final Tile tile = map.getTile(15, 15);
transitive.checkTransitives(tile);
assertEquals(TREE, mapGroup.getGroup(map.getTile(15, 15)));
assertEquals(WATER, mapGroup.getGroup(map.getTile(14, 14)));
assertEquals(GROUND, mapGroup.getGroup(map.getTile(13, 13)));
assertTrue(transitive.getTransitives("a", "b").isEmpty());
assertTrue(transitive.getDirectTransitiveTiles(new Transition(TransitionType.CENTER, "a", "a")).isEmpty());
assertArrayEquals(Arrays.asList(Integer.valueOf(TILE_TRANSITION2)).toArray(), transitive.getDirectTransitiveTiles(new Transition(TransitionType.UP_LEFT, WATER, TREE)).toArray());
assertTrue(config.getFile().delete());
}
Aggregations