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);
}
}
}
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();
}
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;
}
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)));
}
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));
}
Aggregations