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;
}
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);
}
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();
}
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);
}
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);
}
Aggregations