Search in sources :

Example 6 with MapTile

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

the class HandlerPersisterTest method testWithMapCollidable.

/**
 * Test with map and collidable.
 *
 * @throws IOException If error.
 */
@Test
void testWithMapCollidable() throws IOException {
    services.add(new Camera());
    final MapTile map = services.add(new MapTileGame());
    map.create(16, 16, 5, 5);
    final Featurable featurable = factory.create(Medias.create("ObjectColl.xml"));
    featurable.getFeature(Transformable.class).teleport(16, 32);
    handler.add(featurable);
    handler.update(1.0);
    final HandlerPersister persister = new HandlerPersister(services);
    final Media media = Medias.create("persister.data");
    try (FileWriting writing = new FileWriting(media)) {
        persister.save(writing);
    }
    final Services services2 = new Services();
    services2.add(new Camera());
    services2.add(new Factory(services2));
    services2.add(map);
    final Handler handler2 = services2.add(new Handler(services2));
    final HandlerPersister persister2 = new HandlerPersister(services2);
    try (FileReading reading = new FileReading(media)) {
        persister2.load(reading);
    }
    handler2.update(1.0);
    final Featurable featurable2 = handler2.values().iterator().next();
    final Transformable transformable = featurable2.getFeature(Transformable.class);
    assertEquals(16.0, transformable.getX());
    assertEquals(32.0, transformable.getY());
    assertTrue(media.getFile().delete());
}
Also used : FileWriting(com.b3dgs.lionengine.io.FileWriting) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Media(com.b3dgs.lionengine.Media) FileReading(com.b3dgs.lionengine.io.FileReading) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Test(org.junit.jupiter.api.Test)

Example 7 with MapTile

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

the class Scene method update.

@Override
public void update(double extrp) {
    tick.update(extrp);
    tickGen.update(extrp);
    if (tickGen.elapsed(10L)) {
        final MapTile generated = generator.generateMap(parameters, Arrays.asList(Medias.create("forest.png")), Medias.create("sheets.xml"), Medias.create("groups.xml"));
        append.append(generated, 0, 0);
        tickGen.restart();
    }
    if (tick.elapsed(40L)) {
        end();
    }
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile)

Example 8 with MapTile

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

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

the class MapTileCircuitModelTest method createMap.

/**
 * Create the map and configure it.
 *
 * @param tileNumber The number to fill.
 * @return The configured map.
 */
private static MapTile createMap(int tileNumber) {
    final MapTile map = UtilMap.createMap(8);
    map.getFeature(MapTileTransition.class).loadTransitions(configTransitions);
    map.getFeature(MapTileCircuit.class).loadCircuits(configCircuits);
    UtilMap.fill(map, tileNumber);
    return map;
}
Also used : MapTileTransition(com.b3dgs.lionengine.game.feature.tile.map.transition.MapTileTransition) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile)

Example 10 with MapTile

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

the class TransitionsExtractorTest method createMap.

/**
 * Create the map and configure it.
 *
 * @param services The services reference.
 * @param setup The setup.
 * @param tileNumber The number to fill.
 * @return The configured map.
 */
private static MapTile createMap(Services services, Setup setup, int tileNumber) {
    final MapTile map = UtilMap.createMap(tileNumber);
    map.getFeature(MapTileTransition.class).loadTransitions(config);
    return map;
}
Also used : MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile)

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