use of com.b3dgs.lionengine.game.feature.Factory in project lionengine by b3dgs.
the class Scene method load.
@Override
public void load() {
final MapTileGame map = services.create(MapTileGame.class);
map.create(Medias.create("level.png"));
final Camera camera = services.create(Camera.class);
camera.setIntervals(16, 0);
camera.setView(0, 0, getWidth(), getHeight(), getHeight());
camera.setLimits(map);
handler.add(camera);
final MapTileGroup mapGroup = map.addFeatureAndGet(new MapTileGroupModel());
final MapTileCollision mapCollision = map.addFeatureAndGet(new MapTileCollisionModel());
mapCollisionRenderer = map.addFeatureAndGet(new MapTileCollisionRendererModel());
handler.add(map);
mapGroup.loadGroups(Medias.create("groups.xml"));
mapCollision.loadCollisions(Medias.create("formulas.xml"), Medias.create("collisions.xml"));
mapCollisionRenderer.createCollisionDraw();
final MapTileViewer mapViewer = map.addFeatureAndGet(new MapTileViewerModel(services));
mapViewer.addRenderer(mapCollisionRenderer);
mapViewer.prepare(map);
final Factory factory = services.create(Factory.class);
final Mario mario = factory.create(Mario.MEDIA);
mario.getFeature(Transformable.class).teleport(400, 31);
handler.add(mario);
final CameraTracker tracker = new CameraTracker(services);
tracker.track(mario);
handler.add(tracker);
clear.start();
tick.start();
}
use of com.b3dgs.lionengine.game.feature.Factory in project lionengine by b3dgs.
the class Scene method load.
@Override
public void load() {
map.create(Medias.create("forest.png"));
final MapTileGroup mapGroup = map.addFeatureAndGet(new MapTileGroupModel());
final MapTilePath mapPath = map.addFeatureAndGet(new MapTilePathModel());
camera.setView(VIEW_X, VIEW_Y, getWidth() - VIEW_X, getHeight() - VIEW_Y, getHeight());
camera.setLimits(map);
camera.setLocation(160, 96);
map.addFeature(new MapTileViewerModel(services));
handler.add(map);
mapGroup.loadGroups(Medias.create("groups.xml"));
mapPath.loadPathfinding(Medias.create("pathfinding.xml"));
cursor.addImage(0, Medias.create("cursor.png"));
cursor.addImage(1, Medias.create("cursor_order.png"));
cursor.load();
cursor.setGrid(map.getTileWidth(), map.getTileHeight());
cursor.setSync(mouse);
cursor.setViewer(camera);
final Factory factory = services.create(Factory.class);
final Media media = Medias.create("Hud.xml");
final Hud hud = factory.create(media);
handler.add(hud);
final Selector selector = services.get(Selector.class);
selector.addFeatureAndGet(new LayerableModel(4));
selector.setClickableArea(camera);
selector.setSelectionColor(ColorRgba.GREEN);
selector.setClickSelection(MouseAwt.LEFT);
final Featurable peon = factory.create(Medias.create("Peon.xml"));
peon.getFeature(Pathfindable.class).setLocation(20, 10);
handler.add(peon);
transformable = peon.getFeature(Transformable.class);
tick.start();
}
use of com.b3dgs.lionengine.game.feature.Factory in project lionengine by b3dgs.
the class MapTileHelper method importAndSave.
/**
* Import and save the level.
*
* @param levelrip The level rip.
* @param sheetsConfig The file that define the sheets configuration.
* @param out The output media.
* @param mapPersister The persister reference.
*/
public static void importAndSave(Media levelrip, Media sheetsConfig, Media out, MapTilePersister mapPersister) {
final Services services = new Services();
final MapTileGame map = services.create(MapTileGame.class);
map.create(levelrip, sheetsConfig);
map.addFeature(mapPersister);
services.add(new Factory(services));
services.add(new Handler(services));
final HandlerPersister persister = new HandlerPersister(services);
try (FileWriting output = new FileWriting(out)) {
mapPersister.save(output);
persister.save(output);
} catch (final IOException exception) {
Verbose.exception(exception, "Error on saving map !");
}
}
use of com.b3dgs.lionengine.game.feature.Factory in project lionengine by b3dgs.
the class LauncherModelTest method testCheckListener.
/**
* Test check listener conditions.
*/
@Test
void testCheckListener() {
final Media launchableMedia = UtilSetup.createMedia(LaunchableObjectException.class);
final Media launcherMedia = UtilLaunchable.createLauncherMedia(launchableMedia);
final Setup setup = new Setup(launcherMedia);
services.add(new Factory(services));
services.add(new Handler(services));
final AtomicBoolean launchableListener = new AtomicBoolean();
final AtomicBoolean launcherListener = new AtomicBoolean();
final Launcher launcher = new LauncherModel(services, setup) {
@Override
public void addListener(LaunchableListener listener) {
launchableListener.set(true);
}
@Override
public void addListener(LauncherListener listener) {
launcherListener.set(true);
}
};
assertFalse(launchableListener.get());
assertFalse(launcherListener.get());
launcher.checkListener(launcher);
assertFalse(launchableListener.get());
assertFalse(launcherListener.get());
launcher.checkListener((LaunchableListener) l -> l.update(1.0));
assertTrue(launchableListener.get());
assertFalse(launcherListener.get());
launcher.checkListener((LauncherListener) () -> launcher.update(1.0));
launchableListener.set(false);
assertFalse(launchableListener.get());
assertTrue(launcherListener.get());
assertTrue(launchableMedia.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.Factory in project lionengine by b3dgs.
the class HudTest method before.
/**
* Prepare test.
*/
@BeforeEach
public void before() {
services.add(new ContextMock());
services.add(new Handler(services));
services.add(new Factory(services));
services.add(new ViewerMock());
services.add(new Cursor(services));
services.add(new ComponentCollision());
}
Aggregations