Search in sources :

Example 16 with Tile

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

the class Minimap method prepare.

/**
 * Fill minimap surface with tile color configuration.
 *
 * @throws LionEngineException If surface has not been loaded ({@link #load()} may have not been called).
 */
@Override
public void prepare() {
    if (surface == null) {
        throw new LionEngineException(ERROR_SURFACE);
    }
    final Graphic g = surface.createGraphic();
    final int v = map.getInTileHeight();
    final int h = map.getInTileWidth();
    for (int ty = 0; ty < v; ty++) {
        for (int tx = 0; tx < h; tx++) {
            final Tile tile = map.getTile(tx, ty);
            final ColorRgba color = getTileColor(tile);
            if (!NO_TILE.equals(color)) {
                g.setColor(color);
                g.drawRect(tx, v - ty - 1, 0, 0, false);
            }
        }
    }
    g.dispose();
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) LionEngineException(com.b3dgs.lionengine.LionEngineException) Graphic(com.b3dgs.lionengine.graphic.Graphic) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 17 with Tile

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

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

the class MapTileCircuitModelTest method testTransitive.

/**
 * Test the map circuit resolution with transitive.
 */
@Test
void testTransitive() {
    final MapTile map = createMap(TILE_WATER);
    final MapTileGroup mapGroup = map.getFeature(MapTileGroup.class);
    final MapTileCircuit mapCircuit = map.getFeature(MapTileCircuitModel.class);
    map.setTile(5, 5, TILE_ROAD);
    final Tile newTile = map.getTile(5, 5);
    mapCircuit.resolve(newTile);
    assertEquals(ROAD, mapGroup.getGroup(map.getTile(5, 5)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(4, 4)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(5, 4)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(6, 4)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(4, 5)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(6, 5)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(4, 6)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(5, 6)));
    assertEquals(TRANSITION, mapGroup.getGroup(map.getTile(6, 6)));
}
Also used : MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Example 19 with Tile

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

the class TileCollidableModelTest method testFromBottom.

/**
 * Test the collidable from bottom.
 */
@Test
void testFromBottom() {
    final Transformable transformable = createObject(new FeaturableModel(services, setup));
    final AtomicReference<Tile> collided = new AtomicReference<>();
    final TileCollidableListener listener = createListener(collided);
    collidable.addListener(listener);
    transformable.teleport(0.0, -1.0);
    transformable.moveLocation(1.0, 0.0, 3.0);
    collidable.update(1.0);
    assertEquals(map.getTile(0, 0), collided.get());
}
Also used : Transformable(com.b3dgs.lionengine.game.feature.Transformable) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 20 with Tile

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

the class TileCollidableModelTest method testFromLeft.

/**
 * Test the collidable from left.
 */
@Test
void testFromLeft() {
    final Transformable transformable = createObject(new FeaturableModel(services, setup));
    final AtomicReference<Tile> collided = new AtomicReference<>();
    final TileCollidableListener listener = createListener(collided);
    collidable.addListener(listener);
    transformable.teleport(-1.0, 0.0);
    transformable.moveLocation(1.0, 2.0, 0.0);
    collidable.update(1.0);
    assertEquals(map.getTile(0, 0), collided.get());
}
Also used : Transformable(com.b3dgs.lionengine.game.feature.Transformable) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

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