use of com.b3dgs.lionengine.game.feature.tile.map.MapTile 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.map.MapTile in project lionengine by b3dgs.
the class MapTileFogTest method testFog.
/**
* Test the fog.
*/
@Test
void testFog() {
final MapTile map = UtilMap.createMap(5);
services.add(map);
final FovableModel fovable = new FovableModel(services, setup);
final FeaturableModel object = new FeaturableModel(services, setup);
final Transformable transformable = object.addFeatureAndGet(new TransformableModel(services, setup));
transformable.teleport(3, 3);
fovable.prepare(object);
fovable.setFov(1);
final MapTileFog fog = new MapTileFog();
Medias.setLoadFromJar(MapTileFog.class);
fog.create(map.getFeature(MapTileSurface.class), Medias.create("fog.xml"), null);
Medias.setLoadFromJar(null);
final AtomicInteger rtx = new AtomicInteger();
final AtomicInteger rty = new AtomicInteger();
final AtomicInteger count = new AtomicInteger();
final RevealedListener listener = (tx, ty) -> {
rtx.set(tx);
rty.set(ty);
count.incrementAndGet();
};
fog.addListener(listener);
assertEquals(16, fog.getTile(2, 3).getNumber());
assertEquals(16, fog.getTile(3, 3).getNumber());
assertEquals(16, fog.getTile(4, 3).getNumber());
fog.updateFov(fovable);
assertEquals(10, fog.getTile(2, 2).getNumber());
assertEquals(1, fog.getTile(3, 2).getNumber());
assertEquals(11, fog.getTile(4, 2).getNumber());
assertEquals(2, fog.getTile(2, 3).getNumber());
assertEquals(17, fog.getTile(3, 3).getNumber());
assertEquals(3, fog.getTile(4, 3).getNumber());
assertEquals(8, fog.getTile(2, 4).getNumber());
assertEquals(0, fog.getTile(3, 4).getNumber());
assertEquals(9, fog.getTile(4, 4).getNumber());
assertEquals(1, count.get());
assertEquals(3, rtx.get());
assertEquals(3, rty.get());
fog.reset(fovable);
fog.removeListener(listener);
count.set(0);
assertEquals(16, fog.getTile(2, 3).getNumber());
assertEquals(16, fog.getTile(3, 3).getNumber());
assertEquals(16, fog.getTile(4, 3).getNumber());
fog.updateFov(fovable);
assertEquals(0, count.get());
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTile 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());
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.
the class CircuitsConfigTest method testExportsImports.
/**
* Test exports imports.
*
* @throws IOException If error.
*/
@Test
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 MapTileGame map3 = new MapTileGame();
map3.addFeature(new MapTileGroupModel());
map3.create(1, 1, 3, 3);
final CircuitsExtractor extractor = new CircuitsExtractorImpl();
final Map<Circuit, Collection<Integer>> circuits = extractor.getCircuits(Arrays.asList(map, map3));
final Media media = Medias.create("circuit.xml");
CircuitsConfig.exports(media, circuits);
final Map<Circuit, Collection<Integer>> imported = CircuitsConfig.imports(media);
assertEquals(circuits, imported);
assertTrue(media.getFile().delete());
assertTrue(config.getFile().delete());
final Media sheets = Medias.create("sheets.xml");
TileSheetsConfig.exports(sheets, 1, 1, Arrays.asList("sheet.png"));
final Media groups = Medias.create("groups.xml");
TileGroupsConfig.exports(groups, Collections.emptyList());
CircuitsConfig.exports(media, Arrays.asList(Medias.create("level.png")), sheets, groups);
assertTrue(sheets.getFile().delete());
assertTrue(groups.getFile().delete());
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.
the class MapTransitionExtractorTest method testSingleGroup.
/**
* Check the single group transition.
* <p>
* Problem here consists in having two groups without transition group to find tile index at right place.
* </p>
*/
@Test
void testSingleGroup() {
final MapTile map = UtilMap.createMap(7);
UtilMap.fill(map, TILE_WATER);
map.setTile(3, 3, TILE_TRANSITION);
assertNull(get(map, 3, 3));
}
Aggregations