Search in sources :

Example 46 with MapTile

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));
    }
}
Also used : MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile)

Example 47 with MapTile

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());
}
Also used : Medias(com.b3dgs.lionengine.Medias) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilTransformable(com.b3dgs.lionengine.game.feature.UtilTransformable) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) UtilMap(com.b3dgs.lionengine.game.feature.tile.map.UtilMap) Services(com.b3dgs.lionengine.game.feature.Services) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) MapTileSurface(com.b3dgs.lionengine.game.feature.tile.map.MapTileSurface) UtilMapTransition(com.b3dgs.lionengine.game.feature.tile.map.transition.UtilMapTransition) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapTileSurface(com.b3dgs.lionengine.game.feature.tile.map.MapTileSurface) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilTransformable(com.b3dgs.lionengine.game.feature.UtilTransformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Example 48 with MapTile

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());
}
Also used : MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) Media(com.b3dgs.lionengine.Media) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Example 49 with MapTile

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());
}
Also used : MapTileTransition(com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Media(com.b3dgs.lionengine.Media) Collection(java.util.Collection) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Example 50 with MapTile

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));
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Aggregations

MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)58 Test (org.junit.jupiter.api.Test)34 Media (com.b3dgs.lionengine.Media)15 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)11 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)10 Collection (java.util.Collection)9 MapTileGroup (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup)8 MapTileGroupModel (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel)7 MapTileTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)3 Setup (com.b3dgs.lionengine.game.feature.Setup)3 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)3 Featurable (com.b3dgs.lionengine.game.feature.Featurable)2 Transformable (com.b3dgs.lionengine.game.feature.Transformable)2 UtilTransformable (com.b3dgs.lionengine.game.feature.UtilTransformable)2 FileReading (com.b3dgs.lionengine.io.FileReading)2 FileWriting (com.b3dgs.lionengine.io.FileWriting)2 HashSet (java.util.HashSet)2