use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.
the class FovableModelTest method testFovable.
/**
* Test the fovable model.
*/
@Test
void testFovable() {
final MapTile map = UtilMap.createMap(7);
services.add(map);
final Setup setup = new Setup(config);
final Fovable fovable = new FovableModel(services, setup);
final Featurable featurable = new FeaturableModel(services, setup);
final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
transformable.teleport(1, 2);
transformable.setSize(3, 4);
fovable.prepare(featurable);
fovable.setFov(5);
assertEquals(1, fovable.getInTileX());
assertEquals(2, fovable.getInTileY());
assertEquals(3, fovable.getInTileWidth());
assertEquals(4, fovable.getInTileHeight());
assertEquals(5, fovable.getInTileFov());
assertTrue(fovable.canUpdate());
fovable.setCanUpdate(() -> false);
assertFalse(fovable.canUpdate());
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.
the class MapTileCircuitModelTest method testResolution.
/**
* Test the map circuit resolution.
*/
@Test
void testResolution() {
final MapTile map = createMap(TILE_GROUND);
final MapTileGroup mapGroup = map.getFeature(MapTileGroup.class);
final MapTileCircuit mapCircuit = map.getFeature(MapTileCircuitModel.class);
map.setTile(5, 6, TILE_ROAD);
map.setTile(5, 4, TILE_ROAD);
map.setTile(5, 5, TILE_ROAD);
map.setTile(4, 5, TILE_ROAD);
map.setTile(6, 5, TILE_ROAD);
mapCircuit.resolve(map.getTile(5, 5));
assertEquals(ROAD, mapGroup.getGroup(map.getTile(5, 5)));
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.
the class MapGeneratorTest method testGenerator.
/**
* Test the map generator.
*/
@Test
void testGenerator() {
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);
mapViewer.render(g);
assertEquals(16, map.getTileWidth());
assertEquals(16, map.getTileHeight());
assertEquals(64, map.getInTileWidth());
assertEquals(48, map.getInTileHeight());
for (int tx = 0; tx < map.getInTileWidth(); tx++) {
for (int ty = 0; ty < map.getInTileHeight(); ty++) {
assertNotNull(map.getTile(tx, ty));
}
}
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.
the class MapTilePersisterModelTest method testSaveLoad.
/**
* Test the save and load map from file.
*
* @throws IOException If error.
*/
@Test
void testSaveLoad() throws IOException {
final MapTile map = UtilMapTilePersister.createMap();
assertEquals(map.getInTileWidth() * (map.getInTileHeight() - 1), map.getTilesNumber());
final Media level = Medias.create("level");
UtilMapTilePersister.saveMap(map, level);
final MapTile mapLoaded = UtilMapTilePersister.loadMap(level);
assertEquals(map.getTileWidth(), mapLoaded.getTileWidth());
assertEquals(map.getTileHeight(), mapLoaded.getTileHeight());
assertEquals(map.getInTileWidth(), mapLoaded.getInTileWidth());
assertEquals(map.getInTileHeight(), mapLoaded.getInTileHeight());
assertEquals(map.getWidth(), mapLoaded.getWidth());
assertEquals(map.getHeight(), mapLoaded.getHeight());
for (int x = 0; x < mapLoaded.getInTileWidth(); x++) {
for (int y = 0; y < mapLoaded.getInTileHeight(); y++) {
final Tile tile = mapLoaded.getTile(x, y);
if (y == 0) {
assertNull(tile);
} else {
assertNotNull(tile);
assertEquals(x * y, tile.getNumber());
assertEquals(x * mapLoaded.getTileWidth(), tile.getX());
assertEquals(y * mapLoaded.getTileHeight(), tile.getY());
}
}
}
assertEquals(map.getTilesNumber(), mapLoaded.getTilesNumber());
assertTrue(level.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.tile.map.MapTile in project lionengine by b3dgs.
the class MapTilePersisterModelTest method testConstructor.
/**
* Test the constructor with services with map.
*/
@Test
void testConstructor() {
final MapTile map = new MapTileGame();
final MapTilePersister mapPersister = new MapTilePersisterModel();
assertNotNull(mapPersister);
mapPersister.prepare(map);
}
Aggregations