Search in sources :

Example 6 with TileGame

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

the class MapTileFog method create.

/**
 * Create a fog of war from a map.
 *
 * @param map The map reference.
 * @param config The fog configuration.
 * @param sheet The sheet used (can be <code>null</code>).
 */
public void create(MapTile map, Media config, SpriteTiled sheet) {
    this.map.create(map.getTileWidth(), map.getTileHeight(), map.getInTileWidth(), map.getInTileHeight());
    if (sheet != null) {
        this.map.loadSheets(Arrays.asList(sheet));
    }
    for (int i = 0; i < NO_FOG; i++) {
        final String group;
        if (i == FOG) {
            group = FOG_GROUP;
        } else {
            group = TRANSITION_GROUP;
        }
        mapGroup.changeGroup(new TileGame(i, 0, 0, map.getTileWidth(), map.getTileHeight()), group);
    }
    mapGroup.changeGroup(new TileGame(NO_FOG, 0, 0, map.getTileWidth(), map.getTileHeight()), MapTileGroupModel.NO_GROUP_NAME);
    transition.loadTransitions(config);
    for (int tx = 0; tx < map.getInTileWidth(); tx++) {
        for (int ty = 0; ty < map.getInTileHeight(); ty++) {
            this.map.setTile(tx, ty, FOG);
        }
    }
}
Also used : MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) TileGame(com.b3dgs.lionengine.game.feature.tile.TileGame)

Example 7 with TileGame

use of com.b3dgs.lionengine.game.feature.tile.TileGame 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)

Example 8 with TileGame

use of com.b3dgs.lionengine.game.feature.tile.TileGame 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 9 with TileGame

use of com.b3dgs.lionengine.game.feature.tile.TileGame 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 10 with TileGame

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

the class MapTileFog method reset.

/**
 * Reset the revealed tiles to fogged.
 */
public void reset() {
    for (final Tile tile : revealed) {
        final Tile reset = new TileGame(tile.getSheet(), FOG, tile.getX(), tile.getY(), tile.getWidth(), tile.getHeight());
        map.setTile(reset);
    }
    revealed.clear();
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) TileGame(com.b3dgs.lionengine.game.feature.tile.TileGame)

Aggregations

TileGame (com.b3dgs.lionengine.game.feature.tile.TileGame)18 Tile (com.b3dgs.lionengine.game.feature.tile.Tile)8 Test (org.junit.Test)8 MapTile (com.b3dgs.lionengine.game.feature.tile.map.MapTile)3 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)3 MapTileTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition)2 Test (org.junit.jupiter.api.Test)2 GroupTransition (com.b3dgs.lionengine.game.feature.tile.map.transition.GroupTransition)1 Transition (com.b3dgs.lionengine.game.feature.tile.map.transition.Transition)1