Search in sources :

Example 1 with MapTileGroup

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

the class CircuitsExtractorImpl method checkTransitionGroups.

/**
 * Check transitions groups, and create compatible circuit on the fly.
 *
 * @param circuits The circuits collection.
 * @param circuit The circuit found.
 * @param map The map reference.
 * @param ref The tile ref to add.
 */
private static void checkTransitionGroups(Map<Circuit, Collection<TileRef>> circuits, Circuit circuit, MapTile map, TileRef ref) {
    final MapTileGroup mapGroup = map.getFeature(MapTileGroup.class);
    final MapTileTransition mapTransition = map.getFeature(MapTileTransition.class);
    final String group = mapGroup.getGroup(ref);
    for (final String groupTransition : mapGroup.getGroups()) {
        if (mapTransition.getTransitives(group, groupTransition).size() == 1) {
            final Circuit transitiveCircuit = new Circuit(circuit.getType(), group, groupTransition);
            getTiles(circuits, transitiveCircuit).add(ref);
        }
    }
}
Also used : MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) MapTileTransition(com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition)

Example 2 with MapTileGroup

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

the class Scene method load.

@Override
public void load() {
    final MapTileGame map = services.create(MapTileGame.class);
    map.create(Medias.create("level.png"));
    final Camera camera = services.create(Camera.class);
    camera.setIntervals(16, 0);
    camera.setView(0, 0, getWidth(), getHeight(), getHeight());
    camera.setLimits(map);
    handler.add(camera);
    final MapTileGroup mapGroup = map.addFeatureAndGet(new MapTileGroupModel());
    final MapTileCollision mapCollision = map.addFeatureAndGet(new MapTileCollisionModel());
    mapCollisionRenderer = map.addFeatureAndGet(new MapTileCollisionRendererModel());
    handler.add(map);
    mapGroup.loadGroups(Medias.create("groups.xml"));
    mapCollision.loadCollisions(Medias.create("formulas.xml"), Medias.create("collisions.xml"));
    mapCollisionRenderer.createCollisionDraw();
    final MapTileViewer mapViewer = map.addFeatureAndGet(new MapTileViewerModel(services));
    mapViewer.addRenderer(mapCollisionRenderer);
    mapViewer.prepare(map);
    final Factory factory = services.create(Factory.class);
    final Mario mario = factory.create(Mario.MEDIA);
    mario.getFeature(Transformable.class).teleport(400, 31);
    handler.add(mario);
    final CameraTracker tracker = new CameraTracker(services);
    tracker.track(mario);
    handler.add(tracker);
    clear.start();
    tick.start();
}
Also used : MapTileViewer(com.b3dgs.lionengine.game.feature.tile.map.viewer.MapTileViewer) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Factory(com.b3dgs.lionengine.game.feature.Factory) Transformable(com.b3dgs.lionengine.game.feature.Transformable) CameraTracker(com.b3dgs.lionengine.game.feature.CameraTracker) MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) MapTileCollision(com.b3dgs.lionengine.game.feature.tile.map.collision.MapTileCollision) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) Camera(com.b3dgs.lionengine.game.feature.Camera) MapTileCollisionRendererModel(com.b3dgs.lionengine.game.feature.tile.map.collision.MapTileCollisionRendererModel) MapTileViewerModel(com.b3dgs.lionengine.game.feature.tile.map.viewer.MapTileViewerModel) MapTileCollisionModel(com.b3dgs.lionengine.game.feature.tile.map.collision.MapTileCollisionModel)

Example 3 with MapTileGroup

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

the class CircuitsExtractorImpl method getCircuits.

/**
 * Get map tile circuits.
 *
 * @param map The map reference.
 * @return The circuits found with their associated tiles.
 */
private static Map<Circuit, Collection<Integer>> getCircuits(MapTile map) {
    final MapTileGroup mapGroup = map.getFeature(MapTileGroup.class);
    final Map<Circuit, Collection<Integer>> circuits = new HashMap<>();
    final MapCircuitExtractor extractor = new MapCircuitExtractor(map);
    for (int ty = 1; ty < map.getInTileHeight() - 1; ty++) {
        for (int tx = 1; tx < map.getInTileWidth() - 1; tx++) {
            final Tile tile = map.getTile(tx, ty);
            if (tile != null && TileGroupType.CIRCUIT == mapGroup.getType(tile)) {
                checkCircuit(circuits, extractor, map, tile);
            }
        }
    }
    return circuits;
}
Also used : MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) HashMap(java.util.HashMap) Collection(java.util.Collection) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 4 with MapTileGroup

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

the class MapTileCircuitModelTest method testTransitive.

/**
 * Test the map circuit resolution with transitive.
 */
@Test
void testTransitive() {
    final MapTile map = createMap(TILE_WATER);
    final MapTileGroup mapGroup = map.getFeature(MapTileGroup.class);
    final MapTileCircuit mapCircuit = map.getFeature(MapTileCircuitModel.class);
    map.setTile(5, 5, TILE_ROAD);
    final Tile newTile = map.getTile(5, 5);
    mapCircuit.resolve(newTile);
    assertEquals(ROAD, mapGroup.getGroup(map.getTile(5, 5)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(4, 4)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(5, 4)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(6, 4)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(4, 5)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(6, 5)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(4, 6)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(5, 6)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(6, 6)));
}
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) Test(org.junit.jupiter.api.Test)

Example 5 with MapTileGroup

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

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