Search in sources :

Example 41 with Tile

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

the class MapTileCollisionModel method applyConstraints.

/**
 * Apply tile constraints depending of their adjacent collisions.
 */
private void applyConstraints() {
    final Map<Tile, Collection<CollisionFormula>> toRemove = new HashMap<>();
    for (int v = 0; v < map.getInTileHeight(); v++) {
        for (int h = 0; h < map.getInTileWidth(); h++) {
            final Tile tile = map.getTile(h, v);
            if (tile != null) {
                final TileCollision tileCollision = tile.getFeature(TileCollision.class);
                toRemove.put(tile, checkConstraints(tileCollision, h, v));
            }
        }
    }
    for (final Entry<Tile, Collection<CollisionFormula>> current : toRemove.entrySet()) {
        final Tile tile = current.getKey();
        final TileCollision tileCollision = tile.getFeature(TileCollision.class);
        for (final CollisionFormula formula : current.getValue()) {
            tileCollision.removeCollisionFormula(formula);
        }
    }
}
Also used : HashMap(java.util.HashMap) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) Collection(java.util.Collection)

Example 42 with Tile

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

the class MapTilePathModel method addObjectId.

@Override
public void addObjectId(int tx, int ty, Integer id) {
    final Tile tile = map.getTile(tx, ty);
    if (tile != null) {
        final TilePath tilePath = tile.getFeature(TilePath.class);
        tilePath.addObjectId(id);
    }
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 43 with Tile

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

the class UtilMap method fill.

/**
 * Fill map with center tiles from group.
 *
 * @param map The map reference.
 * @param number The tile number.
 */
public static void fill(MapTile map, int number) {
    for (int tx = 0; tx < map.getInTileWidth(); tx++) {
        for (int ty = 0; ty < map.getInTileHeight(); ty++) {
            final Tile tile = map.createTile(SHEET, number, tx, ty);
            map.setTile(tile);
        }
    }
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 44 with Tile

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

the class MapTileGameTest method testClear.

/**
 * Test the map clearing.
 */
@Test
public void testClear() {
    map.create(16, 16, 2, 2);
    final Tile tile = map.createTile(Integer.valueOf(0), 0, 0, 0);
    map.setTile(tile);
    Assert.assertEquals(tile, map.getTile(0, 0));
    map.clear();
    Assert.assertNull(map.getTile(0, 0));
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile) Test(org.junit.Test)

Example 45 with Tile

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

the class MapTileAppenderModel method appendMap.

/**
 * Append the map at specified offset.
 *
 * @param other The map to append.
 * @param offsetX The horizontal offset.
 * @param offsetY The vertical offset.
 */
private void appendMap(MapTile other, int offsetX, int offsetY) {
    for (int v = 0; v < other.getInTileHeight(); v++) {
        final int ty = offsetY + v;
        for (int h = 0; h < other.getInTileWidth(); h++) {
            final int tx = offsetX + h;
            final Tile tile = other.getTile(h, v);
            if (tile != null) {
                map.setTile(tx, ty, tile.getNumber());
            }
        }
    }
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

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