use of com.b3dgs.lionengine.game.feature.Services in project lionengine by b3dgs.
the class CollidableModelTest method testDifferentSizes.
/**
* Test collidable class with different sizes.
*/
@Test
void testDifferentSizes() {
featurable1.addFeature(new MirrorableModel(services, setup));
featurable2.addFeature(new MirrorableModel(services, setup));
final AtomicBoolean auto = new AtomicBoolean();
collidable1.checkListener((CollidableListener) (collidable, with, by) -> auto.set(true));
final Collision collision1 = new Collision("test1", 1, 1, 1, 1, true);
final Collision collision2 = new Collision("test2", 0, 0, 3, 3, false);
collidable1.notifyCollided(collidable2, collision1, collision2);
assertTrue(auto.get());
collidable1.addCollision(collision1);
collidable2.addCollision(collision2);
transformable1.moveLocation(1.0, 1, 1);
transformable2.moveLocation(1.0, 0, 0);
assertEquals(Arrays.asList(new CollisionCouple(collision2, collision1)), collidable2.collide(collidable1));
transformable1.teleport(0.5, 3.5);
assertEquals(Arrays.asList(new CollisionCouple(collision2, collision1)), collidable2.collide(collidable1));
}
use of com.b3dgs.lionengine.game.feature.Services 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.Services 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.Services in project lionengine by b3dgs.
the class DeviceControllerConfig method create.
/**
* Create device controller from configuration.
*
* @param services The services reference (must not be <code>null</code>).
* @param media The media configuration (must not be <code>null</code>).
* @return The created controller.
* @throws LionEngineException If unable to read node.
*/
public static DeviceController create(Services services, Media media) {
final Context context = services.get(Context.class);
final DeviceController controller = new DeviceControllerModel();
final Collection<DeviceControllerConfig> configs = DeviceControllerConfig.imports(services, media);
for (final DeviceControllerConfig config : configs) {
final InputDevice device = context.getInputDevice(config.getDevice());
if (device instanceof DevicePush) {
final DevicePush push = (DevicePush) device;
config.getHorizontal().forEach(h -> controller.addHorizontal(push, new DeviceActionModel(h, push)));
config.getVertical().forEach(v -> controller.addVertical(push, new DeviceActionModel(v, push)));
config.getFire().entrySet().forEach(e -> e.getValue().forEach(c -> controller.addFire(device, e.getKey(), new DeviceActionModel(c, push))));
}
if (device instanceof DevicePointer) {
final DevicePointer pointer = (DevicePointer) device;
controller.addHorizontal(pointer, () -> pointer.getMoveX());
controller.addVertical(pointer, () -> -pointer.getMoveY());
}
if (config.isDisabled()) {
controller.setDisabled(device.getName(), true, true);
}
}
return controller;
}
use of com.b3dgs.lionengine.game.feature.Services in project lionengine by b3dgs.
the class EntityHelper method addAfter.
/*
* Featurable
*/
@Override
public void addAfter(Services services, Setup setup) {
final Routines routines = addFeatureAndGet(new Routines(services, setup));
updating = extrp -> {
state.update(extrp);
attacker.update(extrp);
extractor.update(extrp);
producer.update(extrp);
launchable.update(extrp);
launcher.update(extrp);
routines.update(extrp);
body.update(extrp);
pathfindable.update(extrp);
tileCollidable.update(extrp);
state.postUpdate();
mirrorable.update(extrp);
animatable.update(extrp);
rasterable.update(extrp);
};
rendering = g -> {
pathfindable.render(g);
rasterable.render(g);
collidable.render(g);
routines.render(g);
};
updatingCurrent = updating;
renderingCurrent = rendering;
addFeature(new RefreshableModel(extrp -> {
checker.update(extrp);
updatingCurrent.update(extrp);
}));
addFeature(new DisplayableModel(g -> {
renderingCurrent.render(g);
}));
}
Aggregations