Search in sources :

Example 11 with MapTileGroup

use of com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup in project lionengine by b3dgs.

the class MapTileCircuitModelTest method testResolution.

/**
 * Test the map circuit resolution.
 */
@Test
void testResolution() {
    final MapTile map = createMap(TILE_GROUND);
    final MapTileGroup mapGroup = map.getFeature(MapTileGroup.class);
    final MapTileCircuit mapCircuit = map.getFeature(MapTileCircuitModel.class);
    map.setTile(5, 6, TILE_ROAD);
    map.setTile(5, 4, TILE_ROAD);
    map.setTile(5, 5, TILE_ROAD);
    map.setTile(4, 5, TILE_ROAD);
    map.setTile(6, 5, TILE_ROAD);
    mapCircuit.resolve(map.getTile(5, 5));
    assertEquals(ROAD, mapGroup.getGroup(map.getTile(5, 5)));
}
Also used : MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Example 12 with MapTileGroup

use of com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup 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 13 with MapTileGroup

use of com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup 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)

Aggregations

MapTileGroup (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup)13 MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)8 MapTileGroupModel (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel)6 Media (com.b3dgs.lionengine.Media)4 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)4 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)4 MapTileTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition)4 Test (org.junit.jupiter.api.Test)3 Factory (com.b3dgs.lionengine.game.feature.Factory)2 Transformable (com.b3dgs.lionengine.game.feature.Transformable)2 MapTileTransitionModel (com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransitionModel)2 MapTileViewerModel (com.b3dgs.lionengine.game.feature.tile.map.viewer.MapTileViewerModel)2 HashSet (java.util.HashSet)2 Viewer (com.b3dgs.lionengine.Viewer)1 Camera (com.b3dgs.lionengine.game.feature.Camera)1 CameraTracker (com.b3dgs.lionengine.game.feature.CameraTracker)1 Featurable (com.b3dgs.lionengine.game.feature.Featurable)1 LayerableModel (com.b3dgs.lionengine.game.feature.LayerableModel)1 Hud (com.b3dgs.lionengine.game.feature.collidable.selector.Hud)1 Selector (com.b3dgs.lionengine.game.feature.collidable.selector.Selector)1