Search in sources :

Example 1 with Camera

use of com.b3dgs.lionengine.game.feature.Camera in project lionengine by b3dgs.

the class UtilAssignable method createServices.

/**
 * Create the services.
 *
 * @param clicked The click flag.
 * @param clickNumber The click number recorded.
 * @return The services.
 */
public static Services createServices(AtomicBoolean clicked, AtomicReference<Integer> clickNumber) {
    final Services services = new Services();
    final Camera camera = services.create(Camera.class);
    camera.setView(0, 0, 32, 32, 32);
    services.add(new ContextMock());
    final Cursor cursor = services.add(new Cursor(services) {

        @Override
        public boolean isPushedOnce(Integer click) {
            clickNumber.set(click);
            return clicked.get();
        }
    });
    cursor.setArea(0, 0, 64, 64);
    cursor.setLocation(0, 1);
    return services;
}
Also used : Services(com.b3dgs.lionengine.game.feature.Services) Camera(com.b3dgs.lionengine.game.feature.Camera) ContextMock(com.b3dgs.lionengine.ContextMock) Cursor(com.b3dgs.lionengine.game.Cursor)

Example 2 with Camera

use of com.b3dgs.lionengine.game.feature.Camera in project lionengine by b3dgs.

the class ComponentCollisionTest method prepare.

/**
 * Prepare test.
 */
@BeforeEach
public void prepare() {
    services.add(new Camera());
    featurable1 = new ObjectSelf(services, setup);
    transformable1 = featurable1.addFeatureAndGet(new TransformableModel(services, setup));
    collidable1 = featurable1.addFeatureAndGet(new CollidableModel(services, setup));
    collidable1.setGroup(Integer.valueOf(1));
    collidable1.addAccept(Integer.valueOf(0));
    final Collision collision1 = new Collision("test1", 0, 0, 3, 3, false);
    collidable1.addCollision(collision1);
    featurable2 = CollidableModelTest.createFeaturable(config, services);
    transformable2 = featurable2.getFeature(Transformable.class);
    collidable2 = featurable2.getFeature(Collidable.class);
    collidable2.addAccept(Integer.valueOf(1));
    collidable2.setGroup(Integer.valueOf(0));
    featurable1.addFeature(new MirrorableModel(services, setup));
    featurable2.addFeature(new MirrorableModel(services, setup));
    final Collision collision2 = new Collision("test2", 0, 0, 3, 3, true);
    collidable2.addCollision(collision2);
    handler.addComponent(component);
    handler.add(featurable1);
    handler.add(featurable2);
    handler.add(nonCollidable);
    final CollidableListener listener = (collidable, with, by) -> collide.set(collidable);
    collidable2.addListener(listener);
}
Also used : Medias(com.b3dgs.lionengine.Medias) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) BeforeEach(org.junit.jupiter.api.BeforeEach) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilAssert.assertEquals(com.b3dgs.lionengine.UtilAssert.assertEquals) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) UtilSetup(com.b3dgs.lionengine.game.feature.UtilSetup) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) UtilAssert.assertNull(com.b3dgs.lionengine.UtilAssert.assertNull) Graphics(com.b3dgs.lionengine.graphic.Graphics) Services(com.b3dgs.lionengine.game.feature.Services) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) UtilAssert.assertTrue(com.b3dgs.lionengine.UtilAssert.assertTrue) Media(com.b3dgs.lionengine.Media) Handler(com.b3dgs.lionengine.game.feature.Handler) Geom(com.b3dgs.lionengine.geom.Geom) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Camera(com.b3dgs.lionengine.game.feature.Camera) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Camera(com.b3dgs.lionengine.game.feature.Camera) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with Camera

use of com.b3dgs.lionengine.game.feature.Camera 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 4 with Camera

use of com.b3dgs.lionengine.game.feature.Camera in project lionengine by b3dgs.

the class SceneRasterable method add.

private void add(SetupSurfaceRastered setup, int offsetX) {
    final SpriteAnimated surface = Drawable.loadSpriteAnimated(setup.getSurface(), 4, 4);
    final Featurable featurable = new FeaturableModel(services, setup);
    featurable.addFeature(new MirrorableModel(services, setup));
    featurable.addFeature(new AnimatableModel(services, setup, surface));
    final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
    final Rasterable rasterable = new RasterableModel(services, setup);
    rasterable.setOrigin(Origin.MIDDLE);
    rasterable.setFrameOffsets(1, 2);
    featurable.addFeature(rasterable);
    featurable.addFeature(new RefreshableModel(extrp -> {
        transformable.setLocationY(UtilMath.sin(count) * 240);
        surface.setLocation(camera, transformable);
        rasterable.update(extrp);
        surface.update(extrp);
    }));
    featurable.addFeature(new DisplayableModel(g -> rasterable.render(g)));
    transformable.setLocationX(120 + offsetX);
    handler.add(featurable);
}
Also used : Medias(com.b3dgs.lionengine.Medias) ComponentRefreshable(com.b3dgs.lionengine.game.feature.ComponentRefreshable) RefreshableModel(com.b3dgs.lionengine.game.feature.RefreshableModel) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) ComponentDisplayable(com.b3dgs.lionengine.game.feature.ComponentDisplayable) Drawable(com.b3dgs.lionengine.graphic.drawable.Drawable) Resolution(com.b3dgs.lionengine.Resolution) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) Services(com.b3dgs.lionengine.game.feature.Services) RasterableModel(com.b3dgs.lionengine.game.feature.rasterable.RasterableModel) SetupSurfaceRastered(com.b3dgs.lionengine.game.feature.rasterable.SetupSurfaceRastered) Handler(com.b3dgs.lionengine.game.feature.Handler) UtilMath(com.b3dgs.lionengine.UtilMath) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) Rasterable(com.b3dgs.lionengine.game.feature.rasterable.Rasterable) Graphic(com.b3dgs.lionengine.graphic.Graphic) Sequence(com.b3dgs.lionengine.graphic.engine.Sequence) DisplayableModel(com.b3dgs.lionengine.game.feature.DisplayableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Engine(com.b3dgs.lionengine.Engine) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Context(com.b3dgs.lionengine.Context) Tick(com.b3dgs.lionengine.Tick) Origin(com.b3dgs.lionengine.Origin) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Camera(com.b3dgs.lionengine.game.feature.Camera) SpriteAnimated(com.b3dgs.lionengine.graphic.drawable.SpriteAnimated) RefreshableModel(com.b3dgs.lionengine.game.feature.RefreshableModel) DisplayableModel(com.b3dgs.lionengine.game.feature.DisplayableModel) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) MirrorableModel(com.b3dgs.lionengine.game.feature.MirrorableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) RasterableModel(com.b3dgs.lionengine.game.feature.rasterable.RasterableModel) SpriteAnimated(com.b3dgs.lionengine.graphic.drawable.SpriteAnimated) Transformable(com.b3dgs.lionengine.game.feature.Transformable) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Rasterable(com.b3dgs.lionengine.game.feature.rasterable.Rasterable) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 5 with Camera

use of com.b3dgs.lionengine.game.feature.Camera in project lionengine by b3dgs.

the class TileCollidableModelTest method prepare.

/**
 * Prepare test.
 */
@BeforeEach
public void prepare() {
    services.add(new Camera());
    map.addFeature(new MapTileGroupModel());
    map.create(1, 1, 3, 3);
    UtilMap.setGroups(map);
    UtilMap.fill(map, UtilMap.TILE_GROUND);
    mapCollision = map.addFeatureAndGet(new MapTileCollisionModel());
    mapCollision.prepare(map);
    formulasConfig = UtilConfig.createFormulaConfig(formulaV, formulaH);
    groupsConfig = UtilConfig.createGroupsConfig(group);
    mapCollision.loadCollisions(formulasConfig, groupsConfig);
}
Also used : MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) Camera(com.b3dgs.lionengine.game.feature.Camera) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Camera (com.b3dgs.lionengine.game.feature.Camera)10 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Services (com.b3dgs.lionengine.game.feature.Services)4 ViewerMock (com.b3dgs.lionengine.ViewerMock)3 Cursor (com.b3dgs.lionengine.game.Cursor)3 Featurable (com.b3dgs.lionengine.game.feature.Featurable)3 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)3 Transformable (com.b3dgs.lionengine.game.feature.Transformable)3 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)3 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)3 MapTileGroupModel (com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel)3 ContextMock (com.b3dgs.lionengine.ContextMock)2 Medias (com.b3dgs.lionengine.Medias)2 Handler (com.b3dgs.lionengine.game.feature.Handler)2 MirrorableModel (com.b3dgs.lionengine.game.feature.MirrorableModel)2 Context (com.b3dgs.lionengine.Context)1 Engine (com.b3dgs.lionengine.Engine)1 Media (com.b3dgs.lionengine.Media)1 Origin (com.b3dgs.lionengine.Origin)1 Resolution (com.b3dgs.lionengine.Resolution)1