Search in sources :

Example 26 with Tile

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"));
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile) TileGame(com.b3dgs.lionengine.game.feature.tile.TileGame) Test(org.junit.jupiter.api.Test)

Example 27 with Tile

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;
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) HashSet(java.util.HashSet)

Example 28 with Tile

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);
        }
    }
}
Also used : Transition(com.b3dgs.lionengine.game.feature.tile.map.transition.Transition) GroupTransition(com.b3dgs.lionengine.game.feature.tile.map.transition.GroupTransition) MapTileTransition(com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) TileGame(com.b3dgs.lionengine.game.feature.tile.TileGame)

Example 29 with Tile

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);
    }
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 30 with Tile

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);
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile) HashSet(java.util.HashSet)

Aggregations

Tile (com.b3dgs.lionengine.game.feature.tile.Tile)59 MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)26 Test (org.junit.jupiter.api.Test)13 TileGame (com.b3dgs.lionengine.game.feature.tile.TileGame)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 Transformable (com.b3dgs.lionengine.game.feature.Transformable)7 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)6 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 MapTileGroup (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 LionEngineException (com.b3dgs.lionengine.LionEngineException)2 Media (com.b3dgs.lionengine.Media)2 Force (com.b3dgs.lionengine.game.Force)2 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)2 MapTileTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition)2 SpriteTiled (com.b3dgs.lionengine.graphic.SpriteTiled)2 GroupTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.GroupTransition)1