Search in sources :

Example 1 with Factory

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();
}
Also used : MapTileViewer(com.b3dgs.lionengine.game.feature.tile.map.viewer.MapTileViewer) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Factory(com.b3dgs.lionengine.game.feature.Factory) Transformable(com.b3dgs.lionengine.game.feature.Transformable) CameraTracker(com.b3dgs.lionengine.game.feature.CameraTracker) MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) MapTileCollision(com.b3dgs.lionengine.game.feature.tile.map.collision.MapTileCollision) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) Camera(com.b3dgs.lionengine.game.feature.Camera) MapTileCollisionRendererModel(com.b3dgs.lionengine.game.feature.tile.map.collision.MapTileCollisionRendererModel) MapTileViewerModel(com.b3dgs.lionengine.game.feature.tile.map.viewer.MapTileViewerModel) MapTileCollisionModel(com.b3dgs.lionengine.game.feature.tile.map.collision.MapTileCollisionModel)

Example 2 with Factory

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();
}
Also used : Media(com.b3dgs.lionengine.Media) Factory(com.b3dgs.lionengine.game.feature.Factory) Transformable(com.b3dgs.lionengine.game.feature.Transformable) LayerableModel(com.b3dgs.lionengine.game.feature.LayerableModel) MapTilePath(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.MapTilePath) MapTilePathModel(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.MapTilePathModel) Pathfindable(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable) MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) Hud(com.b3dgs.lionengine.game.feature.collidable.selector.Hud) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) MapTileViewerModel(com.b3dgs.lionengine.game.feature.tile.map.viewer.MapTileViewerModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Selector(com.b3dgs.lionengine.game.feature.collidable.selector.Selector)

Example 3 with Factory

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 !");
    }
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) FileWriting(com.b3dgs.lionengine.io.FileWriting) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) HandlerPersister(com.b3dgs.lionengine.game.feature.HandlerPersister) Factory(com.b3dgs.lionengine.game.feature.Factory) Handler(com.b3dgs.lionengine.game.feature.Handler) IOException(java.io.IOException)

Example 4 with Factory

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());
}
Also used : Medias(com.b3dgs.lionengine.Medias) BeforeEach(org.junit.jupiter.api.BeforeEach) UtilAssert.assertFalse(com.b3dgs.lionengine.UtilAssert.assertFalse) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilAssert.assertTimeout(com.b3dgs.lionengine.UtilAssert.assertTimeout) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) UtilAssert.assertThrowsTimeout(com.b3dgs.lionengine.UtilAssert.assertThrowsTimeout) AfterAll(org.junit.jupiter.api.AfterAll) UtilAssert.assertNull(com.b3dgs.lionengine.UtilAssert.assertNull) Resolution(com.b3dgs.lionengine.Resolution) Services(com.b3dgs.lionengine.game.feature.Services) UtilAssert.assertNotNull(com.b3dgs.lionengine.UtilAssert.assertNotNull) BeforeAll(org.junit.jupiter.api.BeforeAll) Force(com.b3dgs.lionengine.game.Force) Handler(com.b3dgs.lionengine.game.feature.Handler) SourceResolutionDelegate(com.b3dgs.lionengine.graphic.engine.SourceResolutionDelegate) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) Factory(com.b3dgs.lionengine.game.feature.Factory) Localizable(com.b3dgs.lionengine.Localizable) Featurable(com.b3dgs.lionengine.game.feature.Featurable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Media(com.b3dgs.lionengine.Media) Factory(com.b3dgs.lionengine.game.feature.Factory) Handler(com.b3dgs.lionengine.game.feature.Handler) Setup(com.b3dgs.lionengine.game.feature.Setup) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) Test(org.junit.jupiter.api.Test)

Example 5 with Factory

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());
}
Also used : ViewerMock(com.b3dgs.lionengine.ViewerMock) Handler(com.b3dgs.lionengine.game.feature.Handler) Factory(com.b3dgs.lionengine.game.feature.Factory) ComponentCollision(com.b3dgs.lionengine.game.feature.collidable.ComponentCollision) ContextMock(com.b3dgs.lionengine.ContextMock) Cursor(com.b3dgs.lionengine.game.Cursor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Factory (com.b3dgs.lionengine.game.feature.Factory)6 Handler (com.b3dgs.lionengine.game.feature.Handler)4 Transformable (com.b3dgs.lionengine.game.feature.Transformable)4 Media (com.b3dgs.lionengine.Media)2 Featurable (com.b3dgs.lionengine.game.feature.Featurable)2 Services (com.b3dgs.lionengine.game.feature.Services)2 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)2 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)2 MapTileGroup (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup)2 MapTileGroupModel (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel)2 MapTileViewerModel (com.b3dgs.lionengine.game.feature.tile.map.viewer.MapTileViewerModel)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ContextMock (com.b3dgs.lionengine.ContextMock)1 Localizable (com.b3dgs.lionengine.Localizable)1 Medias (com.b3dgs.lionengine.Medias)1 Resolution (com.b3dgs.lionengine.Resolution)1 UtilAssert.assertEquals (com.b3dgs.lionengine.UtilAssert.assertEquals)1 UtilAssert.assertFalse (com.b3dgs.lionengine.UtilAssert.assertFalse)1 UtilAssert.assertNotNull (com.b3dgs.lionengine.UtilAssert.assertNotNull)1 UtilAssert.assertNull (com.b3dgs.lionengine.UtilAssert.assertNull)1