use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.
the class MapTileCollisionComputer method computeCollision.
/**
* Compute the collision from current location.
*
* @param map The map surface reference.
* @param loader The loader reference.
* @param category The collision category.
* @param ox The current horizontal location.
* @param oy The current vertical location.
* @param x The current horizontal location.
* @param y The current vertical location.
* @return The computed collision result, <code>null</code> if none.
*/
private static CollisionResult computeCollision(MapTile map, Function<Tile, List<CollisionFormula>> loader, CollisionCategory category, double ox, double oy, double x, double y) {
final Tile tile = map.getTileAt(getPositionToSide(ox, x), getPositionToSide(oy, y));
if (tile != null) {
Double cx = null;
Double cy = null;
CollisionFormula fx = null;
CollisionFormula fy = null;
final List<CollisionFormula> formulas = loader.apply(tile);
for (int i = 0; i < formulas.size(); i++) {
final CollisionFormula formula = formulas.get(i);
if (cx == null) {
cx = getCollisionX(tile, category, formulas, formula, x, y);
fx = formula;
}
if (cy == null) {
cy = getCollisionY(tile, category, formulas, formula, x, y);
fy = formula;
}
if (cx != null && cy != null) {
break;
}
}
if (cx != null || cy != null) {
return new CollisionResult(cx, cy, tile, fx, fy);
}
}
return null;
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTile 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.MapTile in project lionengine by b3dgs.
the class CircuitsExtractorImpl method getCircuits.
@Override
public Map<Circuit, Collection<Integer>> getCircuits(Collection<MapTile> maps) {
final Map<Circuit, Collection<Integer>> circuits = new HashMap<>();
for (final MapTile map : maps) {
final Map<Circuit, Collection<Integer>> currents = getCircuits(map);
for (final Entry<Circuit, Collection<Integer>> entry : currents.entrySet()) {
final Circuit circuit = entry.getKey();
final Collection<Integer> tiles = entry.getValue();
if (circuits.containsKey(circuit)) {
circuits.get(circuit).addAll(tiles);
} else {
circuits.put(circuit, tiles);
}
}
}
return circuits;
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTile 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));
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.
the class MapTilePersisterModelTest method testInvalidSheet.
/**
* Test the save and load map from file with invalid tile sheet number.
*
* @throws IOException If error.
*/
@Test
public void testInvalidSheet() throws IOException {
final MapTile map = UtilMapTilePersister.createMap();
final File levelFile = folder.newFile();
final Media level = Medias.get(levelFile);
map.setTile(map.createTile(Integer.valueOf(Integer.MAX_VALUE), 0, 0, 0));
UtilMapTilePersister.saveMap(map, level);
try {
final MapTile mapLoaded = UtilMapTilePersister.loadMap(level);
Assert.assertNull(mapLoaded);
} catch (final IOException exception) {
// Success
Assert.assertNotNull(exception);
}
Assert.assertTrue(levelFile.delete());
}
Aggregations