use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.
the class TransitionsExtractorTest method createMap.
/**
* Create the map and configure it.
*
* @param tileNumber The number to fill.
* @return The configured map.
*/
private static MapTile createMap(int tileNumber) {
final MapTile map = UtilMap.createMap(tileNumber);
map.getFeature(MapTileTransition.class).loadTransitions(config);
return map;
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.
the class CircuitConfigTest method testExportsImports.
/**
* Test exports imports.
*
* @throws IOException If error.
*/
@Test
public void testExportsImports() throws IOException {
final Media config = UtilMapTransition.createTransitions();
final MapTile map = UtilMap.createMap(7);
map.getFeature(MapTileTransition.class).loadTransitions(config);
UtilMap.fill(map, UtilMap.TILE_GROUND);
UtilMap.fill(map, UtilMap.TILE_ROAD, UtilMap.TILE_ROAD, 3);
final MapTile map3 = new MapTileGame();
map3.addFeature(new MapTileGroupModel());
map3.create(1, 1, 3, 3);
final CircuitsExtractor extractor = new CircuitsExtractorImpl();
final Map<Circuit, Collection<TileRef>> circuits = extractor.getCircuits(Arrays.asList(map, map3));
final Media media = Medias.create("circuit.xml");
CircuitsConfig.exports(media, circuits);
final Map<Circuit, Collection<TileRef>> imported = CircuitsConfig.imports(media);
Assert.assertEquals(circuits, imported);
Assert.assertTrue(media.getFile().delete());
Assert.assertTrue(config.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.
the class MapCircuitExtractorTest method testDifferentSheet.
/**
* Check the circuit with different sheets.
*/
@Test
public void testDifferentSheet() {
final MapTile map = UtilMap.createMap(7);
UtilMap.fill(map, TILE_GROUND);
map.setTile(map.createTile(Integer.valueOf(1), TILE_ROAD, 3, 3));
Assert.assertEquals(new Circuit(CircuitType.BLOCK, MapTileGroupModel.NO_GROUP_NAME, GROUND), get(map, 3, 3));
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTile 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.map.MapTile in project lionengine by b3dgs.
the class HandlerPersisterTest method testWithMap.
/**
* Test with map.
*
* @throws IOException If error.
*/
@Test
void testWithMap() throws IOException {
services.add(new Camera());
final MapTile map = services.add(new MapTileGame());
map.create(16, 16, 5, 5);
final Featurable featurable = factory.create(Medias.create("ObjectFeatures.xml"));
featurable.getFeature(Transformable.class).teleport(16, 32);
handler.add(featurable);
handler.update(1.0);
final HandlerPersister persister = new HandlerPersister(services);
final Media media = Medias.create("persister.data");
try (FileWriting writing = new FileWriting(media)) {
persister.save(writing);
}
final Services services2 = new Services();
services2.add(new Factory(services2));
services2.add(map);
final Handler handler2 = services2.add(new Handler(services2));
final HandlerPersister persister2 = new HandlerPersister(services2);
try (FileReading reading = new FileReading(media)) {
persister2.load(reading);
}
handler2.update(1.0);
final Featurable featurable2 = handler2.values().iterator().next();
final Transformable transformable = featurable2.getFeature(Transformable.class);
assertEquals(16.0, transformable.getX());
assertEquals(32.0, transformable.getY());
assertTrue(media.getFile().delete());
}
Aggregations