Search in sources :

Example 1 with MapTile

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

the class PrefMapFill method apply.

/*
     * Preference
     */
@Override
public void apply(MapTile map) {
    final double tw = map.getTileWidth();
    final double th = map.getTileHeight();
    for (int tx = 0; tx < map.getInTileWidth(); tx++) {
        final double x = tx * tw;
        for (int ty = 0; ty < map.getInTileHeight(); ty++) {
            final double y = ty * th;
            final Tile tile = map.createTile(sheet, number, x, y);
            map.setTile(tile);
        }
    }
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 2 with MapTile

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

the class FogOfWar method renderTile.

/*
     * MapTileRenderer
     */
@Override
public void renderTile(Graphic g, MapTile map, Tile tile, int x, int y) {
    final int tx = tile.getInTileX();
    final int ty = tile.getInTileY();
    final Tile fogTile = mapFogged.getTile(tx, ty);
    if (fogMap && fogTile != null && fogTile.getNumber() != MapTileFog.NO_FOG) {
        fogTiles.setLocation(x, y);
        fogTiles.setTile(fogTile.getNumber());
        fogTiles.render(g);
    }
    final Tile hideTile = mapHidden.getTile(tx, ty);
    if (hideMap && hideTile != null && hideTile.getNumber() != MapTileFog.NO_FOG) {
        hideTiles.setTile(hideTile.getNumber());
        hideTiles.setLocation(x, y);
        hideTiles.render(g);
    }
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 3 with MapTile

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

the class MapTransitionExtractorTest method testDifferentSheet.

/**
 * Check the transition with different sheets.
 */
@Test
public void testDifferentSheet() {
    final MapTile map = UtilMap.createMap(7);
    UtilMap.fill(map, TILE_WATER);
    map.setTile(map.createTile(Integer.valueOf(1), TILE_WATER, 3, 3));
    Assert.assertNull(get(map, 3, 3));
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.Test)

Example 4 with MapTile

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

the class TransitionConfigTest method testExportsImports.

/**
 * Test exports and imports.
 *
 * @throws IOException If error.
 */
@Test
public void testExportsImports() throws IOException {
    final MapTile map = UtilMap.createMap(7);
    UtilMap.fill(map, UtilMap.TILE_WATER);
    UtilMap.fill(map, UtilMap.TILE_WATER, UtilMap.TILE_TRANSITION, 3);
    final MapTile map2 = UtilMap.createMap(7);
    UtilMap.fill(map, UtilMap.TILE_WATER);
    UtilMap.fill(map, UtilMap.TILE_GROUND, UtilMap.TILE_TRANSITION, 3);
    final MapTile map3 = new MapTileGame();
    map3.addFeature(new MapTileGroupModel());
    map3.create(1, 1, 3, 3);
    final TransitionsExtractor extractor = new TransitionsExtractorImpl();
    final Map<Transition, Collection<TileRef>> transitions = extractor.getTransitions(Arrays.asList(map, map2, map3));
    final Media media = Medias.create("transition.xml");
    TransitionsConfig.exports(media, transitions);
    Assert.assertEquals(transitions, TransitionsConfig.imports(media));
    Assert.assertTrue(media.getFile().delete());
}
Also used : MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Media(com.b3dgs.lionengine.Media) Collection(java.util.Collection) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.Test)

Example 5 with MapTile

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

the class PrefMapRegion method apply.

/*
     * Preference
     */
@Override
public void apply(MapTile map) {
    final MapTileTransition mapTransition = map.getFeature(MapTileTransition.class);
    final int sx = area.getInTileX();
    final int sy = area.getInTileY();
    final int ex = UtilMath.clamp(area.getInTileWidth(), 0, map.getInTileWidth() - 1);
    final int ey = UtilMath.clamp(area.getInTileHeight(), 0, map.getInTileHeight() - 1);
    int remaining = count;
    while (remaining > 0) {
        final int tx = UtilRandom.getRandomInteger(sx, ex);
        final int ty = UtilRandom.getRandomInteger(sy, ey);
        final int size = UtilRandom.getRandomInteger(maxSize);
        final int halfBottom = (int) Math.floor(size / 2.0);
        final int halfTop = (int) Math.ceil(size / 2.0);
        for (int ox = -halfBottom; ox < halfTop; ox++) {
            for (int oy = -halfBottom; oy < halfTop; oy++) {
                final int ntx = UtilMath.clamp(tx + ox, sx, ex);
                final int nty = UtilMath.clamp(ty + oy, sy, ey);
                final Tile tile = new TileGame(number, ntx, nty, map.getTileWidth(), map.getTileHeight());
                map.setTile(tile.getInTileX(), tile.getInTileY(), number);
                mapTransition.resolve(tile);
            }
        }
        remaining--;
    }
}
Also used : MapTileTransition(com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) TileGame(com.b3dgs.lionengine.game.feature.tile.TileGame)

Aggregations

MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)58 Test (org.junit.jupiter.api.Test)34 Media (com.b3dgs.lionengine.Media)15 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)11 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)10 Collection (java.util.Collection)9 MapTileGroup (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup)8 MapTileGroupModel (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel)7 MapTileTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)3 Setup (com.b3dgs.lionengine.game.feature.Setup)3 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)3 Featurable (com.b3dgs.lionengine.game.feature.Featurable)2 Transformable (com.b3dgs.lionengine.game.feature.Transformable)2 UtilTransformable (com.b3dgs.lionengine.game.feature.UtilTransformable)2 FileReading (com.b3dgs.lionengine.io.FileReading)2 FileWriting (com.b3dgs.lionengine.io.FileWriting)2 HashSet (java.util.HashSet)2