Search in sources :

Example 56 with Tile

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

the class TransitiveGroup method checkTransitives.

/**
 * Check transitive tiles.
 *
 * @param tile The tile reference.
 * @param tx The horizontal index neighbor.
 * @param ty The vertical index neighbor.
 */
private void checkTransitives(Tile tile, int tx, int ty) {
    final Tile neighbor = map.getTile(tx, ty);
    final String group = mapGroup.getGroup(neighbor);
    if (neighbor != null) {
        for (final GroupTransition current : getTransitives(mapGroup.getGroup(tile), mapGroup.getGroup(neighbor))) {
            for (final Integer number : mapGroup.getGroup(current.getOut())) {
                checkTransitives(neighbor, group, current, number);
            }
            break;
        }
    }
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 57 with Tile

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

the class MapTileViewerModel method renderTile.

/**
 * Render the tile from location.
 *
 * @param g The graphic output.
 * @param tx The horizontal tile location.
 * @param ty The vertical tile location.
 * @param viewX The horizontal view offset.
 * @param viewY The vertical view offset.
 */
private void renderTile(Graphic g, int tx, int ty, double viewX, double viewY) {
    final Tile tile = map.getTile(tx, ty);
    if (tile != null) {
        final int x = (int) Math.round(tile.getX() - viewX);
        final int y = (int) Math.round(-tile.getY() + viewY - tile.getHeight());
        for (int i = 0; i < renderers.size(); i++) {
            renderers.get(i).renderTile(g, tile, x, y);
        }
    }
}
Also used : Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 58 with Tile

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

the class MapTileGameTest method testSetGetTile.

/**
 * Test map set and get tile.
 */
@Test
void testSetGetTile() {
    map.create(16, 16, 3, 3);
    map.loadSheets(new ArrayList<SpriteTiled>());
    assertEquals(0, map.getTilesNumber());
    assertNull(map.getTile(0, 0));
    assertNull(map.getTileAt(51.0, 68.0));
    map.setTile(0, 0, 0);
    final Tile tile = map.getTile(0, 0);
    assertEquals(1, map.getTilesNumber());
    assertEquals(tile, map.getTile(0, 0));
    assertEquals(tile, map.getTile(Geom.createLocalizable(0, 0), 0, 0));
    assertEquals(tile, map.getTileAt(3.0, 6.0));
    assertEquals(Arrays.asList(tile), map.getTilesHit(-1, -1, 1, 1));
}
Also used : SpriteTiled(com.b3dgs.lionengine.graphic.drawable.SpriteTiled) Tile(com.b3dgs.lionengine.game.feature.tile.Tile) Test(org.junit.jupiter.api.Test)

Example 59 with Tile

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

the class CollisionResultTest method testNoResult.

/**
 * Test the collision no result.
 */
@Test
void testNoResult() {
    final Tile tile = new TileGame(1, 3, 4, 1, 1);
    CollisionResult result = new CollisionResult(null, null, tile, null, null);
    assertFalse(result.startWithX("formula"));
    assertFalse(result.startWithY("formulaZ"));
    assertFalse(result.contains("formula"));
    result = new CollisionResult(null, null, tile, formulaX, null);
    assertTrue(result.startWithX("formula"));
    assertFalse(result.startWithX("formulaZ"));
    assertFalse(result.startWithY("formula"));
    assertFalse(result.startWithY("formulaZ"));
    assertTrue(result.contains("formula"));
    assertFalse(result.contains("formulaZ"));
    result = new CollisionResult(null, null, tile, null, formulaY);
    assertFalse(result.startWithX("formula"));
    assertFalse(result.startWithX("formulaZ"));
    assertTrue(result.startWithY("formula"));
    assertFalse(result.startWithY("formulaZ"));
    assertTrue(result.contains("formula"));
    assertFalse(result.contains("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)

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