use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.
the class CollisionResultTest method testResult.
/**
* Test the collision result.
*/
@Test
void testResult() {
final Double x = Double.valueOf(1.0);
final Double y = Double.valueOf(2.0);
final Tile tile = new TileGame(1, 3, 4, 1, 1);
final CollisionResult result = new CollisionResult(x, y, tile, formulaX, formulaY);
assertEquals(x, result.getX());
assertEquals(y, result.getY());
assertEquals(tile, result.getTile());
assertTrue(result.startWithX("formula"));
assertFalse(result.startWithY("formulaZ"));
assertTrue(result.endWithX("X"));
assertFalse(result.endWithY("Z"));
assertTrue(result.contains("formula"));
assertFalse(result.contains("formulaZ"));
assertTrue(result.containsX("formulaX"));
assertFalse(result.containsY("formulaZ"));
}
use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.
the class MapTransitionExtractor method getSharedNeigbors.
/**
* Get the neighbors in commons between two tiles.
*
* @param tile1 The first tile.
* @param tile2 The second tile.
* @return The neighbors in common (should be 2).
*/
private Collection<Tile> getSharedNeigbors(Tile tile1, Tile tile2) {
final Collection<Tile> neighbors1 = map.getNeighbors(tile1);
final Collection<Tile> neighbors2 = map.getNeighbors(tile2);
final Collection<Tile> sharedNeighbors = new HashSet<>(2);
for (final Tile neighbor : neighbors1) {
if (neighbors2.contains(neighbor)) {
sharedNeighbors.add(neighbor);
}
}
neighbors1.clear();
neighbors2.clear();
return sharedNeighbors;
}
use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.
the class MapTileCircuitModel method updateTransitiveTile.
/**
* Update tile.
*
* @param tile The tile reference.
*/
private void updateTransitiveTile(Tile tile) {
final Circuit circuit = extractor.getCircuit(tile);
if (circuit == null || !circuits.containsKey(circuit)) {
final String group = getTransitiveGroup(circuit, tile);
if (group != null) {
final int old = tile.getNumber();
final Integer ref = mapTransition.getTiles(new Transition(TransitionType.CENTER, group, group)).iterator().next();
final Tile newTile = new TileGame(ref.intValue(), tile.getInTileX(), tile.getInTileY(), tile.getWidth(), tile.getHeight());
map.setTile(newTile.getInTileX(), newTile.getInTileY(), newTile.getNumber());
mapTransition.resolve(newTile);
map.setTile(newTile.getInTileX(), newTile.getInTileY(), old);
}
}
}
use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.
the class MapTileCircuitModel method updateTile.
/**
* Update tile.
*
* @param tile The tile reference.
* @param ox The horizontal offset to update.
* @param oy The vertical offset to update.
*/
private void updateTile(Tile tile, int ox, int oy) {
final int tx = tile.getInTileX();
final int ty = tile.getInTileY();
final Tile neighbor = map.getTile(tx + ox, ty + oy);
if (neighbor != null) {
updateNeigbor(tile, neighbor);
}
}
use of com.b3dgs.lionengine.game.feature.tile.Tile in project lionengine by b3dgs.
the class MapTileCircuitModel method getTransitiveGroup.
/**
* Get the transitive group by replacing the transition group name with the plain one.
*
* @param initialCircuit The initial circuit.
* @param tile The tile reference.
* @return The plain group name.
*/
private String getTransitiveGroup(Circuit initialCircuit, Tile tile) {
final Set<Circuit> circuitSet = circuits.keySet();
final Collection<String> groups = new HashSet<>(circuitSet.size());
final String groupIn = mapGroup.getGroup(tile);
for (final Circuit circuit : circuitSet) {
final String groupOut = circuit.getOut();
for (final Tile neighbor : map.getNeighbors(tile)) {
final String groupNeighbor = mapGroup.getGroup(neighbor);
if (groupNeighbor.equals(groupOut) && !groupNeighbor.equals(groupIn)) {
return groupOut;
}
}
groups.add(groupOut);
}
return getShortestTransitiveGroup(groups, initialCircuit);
}
Aggregations