Search in sources :

Example 11 with MapTileGroupModel

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

the class ServicesTest method testCreateGet.

/**
 * Test the service creation.
 */
@Test
public void testCreateGet() {
    final Services services = new Services();
    final Camera camera = services.create(Camera.class);
    final Factory factory = services.create(Factory.class);
    final MapTile map = services.create(MapTileGame.class);
    final MapTileGroup mapGroup = map.addFeatureAndGet(new MapTileGroupModel());
    Assert.assertEquals(services, services.get(Services.class));
    Assert.assertEquals(camera, services.get(Viewer.class));
    Assert.assertEquals(factory, services.get(Factory.class));
    Assert.assertEquals(map, services.get(MapTile.class));
    Assert.assertEquals(mapGroup, map.getFeature(MapTileGroup.class));
}
Also used : MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) Viewer(com.b3dgs.lionengine.Viewer) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.Test)

Example 12 with MapTileGroupModel

use of com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel 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());
}
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.Test)

Example 13 with MapTileGroupModel

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

the class Scene method load.

@Override
public void load() {
    map.create(Medias.create("level.png"));
    camera.setView(0, 0, getWidth(), getHeight(), getHeight());
    camera.setLocation(160, 96);
    map.create(Medias.create("level.png"));
    map.addFeature(new MapTileViewerModel(services));
    map.addFeatureAndGet(new MapTileGroupModel()).loadGroups(Medias.create("groups.xml"));
    map.addFeatureAndGet(new MapTilePathModel()).loadPathfinding(Medias.create("pathfinding.xml"));
    camera.setLimits(map);
    handler.add(map);
    final Featurable peon1 = factory.create(Peon.MEDIA);
    peon1.getFeature(Pathfindable.class).setLocation(20, 16);
    peon1.getFeature(Pathfindable.class).setDestination(23, 12);
    peon1.getFeature(Pathfindable.class).pointTo(1, 2);
    handler.add(peon1);
    peon2 = factory.create(Peon.MEDIA);
    peon2.getFeature(Pathfindable.class).setLocation(22, 8);
    handler.add(peon2);
    final Featurable peon3 = factory.create(Peon.MEDIA);
    peon3.getFeature(Pathfindable.class).setLocation(25, 10);
    assertTrue(peon3.getFeature(Pathfindable.class).isPathAvailable(23, 12));
    peon3.getFeature(Pathfindable.class).setDestination(23, 12);
    handler.add(peon3);
    peon2.getFeature(Pathfindable.class).setIgnoreId(peon3.getFeature(Identifiable.class).getId(), true);
    peon2.getFeature(Pathfindable.class).pointTo(map.getTile(25, 25));
    assertEquals(Orientation.NORTH_EAST, peon2.getFeature(Pathfindable.class).getOrientation());
    peon2.getFeature(Pathfindable.class).setOrientation(Orientation.NORTH_WEST);
    assertEquals(Orientation.NORTH_WEST, peon2.getFeature(Pathfindable.class).getOrientation());
    peon2.getFeature(Pathfindable.class).addListener(listener);
    tick.start();
}
Also used : MapTilePathModel(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.MapTilePathModel) Pathfindable(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) MapTileViewerModel(com.b3dgs.lionengine.game.feature.tile.map.viewer.MapTileViewerModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 14 with MapTileGroupModel

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

the class Scene method load.

@Override
public void load() {
    map.create(Medias.create("forest.png"));
    final MapTileGroup mapGroup = map.addFeatureAndGet(new MapTileGroupModel());
    final MapTilePath mapPath = map.addFeatureAndGet(new MapTilePathModel());
    camera.setView(VIEW_X, VIEW_Y, getWidth() - VIEW_X, getHeight() - VIEW_Y, getHeight());
    camera.setLimits(map);
    camera.setLocation(160, 96);
    map.addFeature(new MapTileViewerModel(services));
    handler.add(map);
    mapGroup.loadGroups(Medias.create("groups.xml"));
    mapPath.loadPathfinding(Medias.create("pathfinding.xml"));
    cursor.addImage(0, Medias.create("cursor.png"));
    cursor.addImage(1, Medias.create("cursor_order.png"));
    cursor.load();
    cursor.setGrid(map.getTileWidth(), map.getTileHeight());
    cursor.setSync(mouse);
    cursor.setViewer(camera);
    final Factory factory = services.create(Factory.class);
    final Media media = Medias.create("Hud.xml");
    final Hud hud = factory.create(media);
    handler.add(hud);
    final Selector selector = services.get(Selector.class);
    selector.addFeatureAndGet(new LayerableModel(4));
    selector.setClickableArea(camera);
    selector.setSelectionColor(ColorRgba.GREEN);
    selector.setClickSelection(MouseAwt.LEFT);
    final Featurable peon = factory.create(Medias.create("Peon.xml"));
    peon.getFeature(Pathfindable.class).setLocation(20, 10);
    handler.add(peon);
    transformable = peon.getFeature(Transformable.class);
    tick.start();
}
Also used : Media(com.b3dgs.lionengine.Media) Factory(com.b3dgs.lionengine.game.feature.Factory) Transformable(com.b3dgs.lionengine.game.feature.Transformable) LayerableModel(com.b3dgs.lionengine.game.feature.LayerableModel) MapTilePath(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.MapTilePath) MapTilePathModel(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.MapTilePathModel) Pathfindable(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable) MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) Hud(com.b3dgs.lionengine.game.feature.collidable.selector.Hud) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) MapTileViewerModel(com.b3dgs.lionengine.game.feature.tile.map.viewer.MapTileViewerModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Selector(com.b3dgs.lionengine.game.feature.collidable.selector.Selector)

Example 15 with MapTileGroupModel

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

the class MapGeneratorTest method prepare.

/**
 * Prepare test.
 */
@BeforeEach
public void prepare() {
    map.create(Medias.create("forest.png"));
    mapViewer.prepare(map);
    final Media media = Medias.create("transitions.xml");
    TransitionsConfig.exports(media, Arrays.asList(Medias.create("forest.png")), Medias.create("sheets.xml"), Medias.create("groups.xml"));
    map.addFeatureAndGet(new MapTileGroupModel()).loadGroups(Medias.create("groups.xml"));
    map.addFeatureAndGet(new MapTileTransitionModel()).loadTransitions(Medias.create("transitions.xml"));
    map.addFeatureAndGet(new MapTileCircuitModel()).loadCircuits(Medias.create("circuits.xml"));
    camera.setView(0, 0, 640, 480, 480);
    camera.setLimits(map);
    parameters.add(new PrefMapSize(16, 16, 64, 48)).add(new PrefMapFill(0)).add(new PrefMapRegion(12, new TileArea(0, 0, 8, 48), 4, 60)).add(new PrefMapRegion(12, new TileArea(56, 0, 64, 48), 4, 60)).add(new PrefMapRegion(12, new TileArea(0, 0, 64, 8), 4, 60)).add(new PrefMapRegion(12, new TileArea(0, 40, 64, 48), 4, 60)).add(new PrefMapRegion(29, new TileArea(12, 12, 56, 42), 2, 250)).add(new PrefMapRegion(12, new TileArea(24, 24, 40, 40), 2, 80)).add(new PrefMapRegion(0, new TileArea(4, 4, 60, 40), 1, 100));
    assertTrue(media.getFile().delete());
}
Also used : Media(com.b3dgs.lionengine.Media) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) MapTileTransitionModel(com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransitionModel) MapTileCircuitModel(com.b3dgs.lionengine.game.feature.tile.map.transition.circuit.MapTileCircuitModel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MapTileGroupModel (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel)19 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)11 Media (com.b3dgs.lionengine.Media)9 MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)7 MapTileGroup (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 MapTileTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition)4 MapTileTransitionModel (com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransitionModel)4 Collection (java.util.Collection)4 Camera (com.b3dgs.lionengine.game.feature.Camera)3 MapTileCircuitModel (com.b3dgs.lionengine.game.feature.tile.map.transition.circuit.MapTileCircuitModel)3 MapTileViewerModel (com.b3dgs.lionengine.game.feature.tile.map.viewer.MapTileViewerModel)3 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 Factory (com.b3dgs.lionengine.game.feature.Factory)2 Featurable (com.b3dgs.lionengine.game.feature.Featurable)2 Transformable (com.b3dgs.lionengine.game.feature.Transformable)2 MapTilePathModel (com.b3dgs.lionengine.game.feature.tile.map.pathfinding.MapTilePathModel)2 Pathfindable (com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable)2 HashSet (java.util.HashSet)2