use of com.b3dgs.lionengine.game.feature.Services in project lionengine by b3dgs.
the class UtilActionnable method createServices.
/**
* Create the services.
*
* @param clicked The click flag.
* @param clickNumber The click number recorded.
* @return The services.
*/
public static Services createServices(final AtomicBoolean clicked, final AtomicInteger clickNumber) {
final Services services = new Services();
final Cursor cursor = new Cursor() {
@Override
public boolean hasClickedOnce(int click) {
clickNumber.set(click);
return clicked.get();
}
};
cursor.setArea(0, 0, 32, 32);
cursor.setLocation(0, 1);
services.add(cursor);
return services;
}
use of com.b3dgs.lionengine.game.feature.Services 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(final AtomicBoolean clicked, final AtomicInteger clickNumber) {
final Services services = new Services();
final Camera camera = services.create(Camera.class);
camera.setView(0, 0, 32, 32, 32);
final Cursor cursor = services.add(new Cursor() {
@Override
public boolean hasClickedOnce(int 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.Services in project lionengine by b3dgs.
the class UtilActionnable 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();
services.add(new ContextMock());
final Cursor cursor = new Cursor(services) {
@Override
public boolean isPushedOnce(Integer click) {
clickNumber.set(click);
return clicked.get();
}
};
cursor.setArea(0, 0, 32, 32);
cursor.setLocation(0, 1);
services.add(cursor);
return services;
}
use of com.b3dgs.lionengine.game.feature.Services in project lionengine by b3dgs.
the class BodyConfigTest method testExportsImports.
/**
* Test exports imports.
*/
@Test
void testExportsImports() {
final Media media = Medias.create("Object.xml");
final Xml root = new Xml("test");
final Xml node = root.createChild(BodyConfig.NODE_BODY);
node.writeDouble(BodyConfig.ATT_GRAVITY, 1.0);
node.writeDouble(BodyConfig.ATT_GRAVITY_MAX, 2.0);
root.save(media);
final Body body = new BodyModel(new Services(), new Setup(media));
BodyConfig.exports(root, body);
final BodyConfig config = BodyConfig.imports(new Setup(media));
assertEquals(1.0, config.getGravity());
assertEquals(2.0, config.getGravityMax());
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.Services in project lionengine by b3dgs.
the class FogOfWarTest method testFogOfWar.
/**
* Test the fog of war.
*/
@Test
void testFogOfWar() {
final Setup setup = new Setup(config);
final FeaturableModel object = new FeaturableModel(services, setup);
final Transformable transformable = object.addFeatureAndGet(new TransformableModel(services, setup));
final FovableModel fovable = object.addFeatureAndGet(new FovableModel(services, setup));
fovable.prepare(object);
fovable.setFov(1);
Medias.setLoadFromJar(MapTileFog.class);
fog.setEnabled(true, true);
fog.create(Medias.create("fog.xml"));
Medias.setLoadFromJar(null);
final AtomicInteger rtx = new AtomicInteger();
final AtomicInteger rty = new AtomicInteger();
final AtomicInteger count = new AtomicInteger();
final RevealedListener listener = (tx, ty) -> {
rtx.set(tx);
rty.set(ty);
count.incrementAndGet();
};
fog.addListener(listener);
assertFalse(fog.isFogged(2, 3));
assertFalse(fog.isFogged(3, 3));
assertFalse(fog.isFogged(4, 3));
assertFalse(fog.isVisible(map.getTile(2, 3)));
assertFalse(fog.isVisible(map.getTile(3, 3)));
assertFalse(fog.isVisible(map.getTile(4, 3)));
assertFalse(fog.isVisited(2, 3));
assertFalse(fog.isVisited(3, 3));
assertFalse(fog.isVisited(4, 3));
assertFalse(fog.isVisited(Geom.createArea(3, 3, 1, 1)));
transformable.teleport(3, 3);
fog.update(fovable);
assertTrue(fog.isFogged(2, 3));
assertFalse(fog.isFogged(3, 3));
assertTrue(fog.isFogged(4, 3));
assertFalse(fog.isVisible(map.getTile(2, 3)));
assertTrue(fog.isVisible(map.getTile(3, 3)));
assertFalse(fog.isVisible(map.getTile(4, 3)));
assertFalse(fog.isVisited(2, 3));
assertTrue(fog.isVisited(3, 3));
assertFalse(fog.isVisited(4, 3));
assertTrue(fog.isVisited(Geom.createArea(3, 3, 1, 1)));
assertEquals(1, count.get());
assertEquals(3, rtx.get());
assertEquals(3, rty.get());
transformable.setLocation(6, 6);
fog.removeListener(listener);
count.set(0);
fog.update(fovable);
assertFalse(fog.isFogged(2, 3));
assertTrue(fog.isFogged(3, 3));
assertTrue(fog.isFogged(4, 3));
assertFalse(fog.isVisible(map.getTile(2, 3)));
assertFalse(fog.isVisible(map.getTile(3, 3)));
assertFalse(fog.isVisible(map.getTile(4, 3)));
assertFalse(fog.isVisited(2, 3));
assertTrue(fog.isVisited(3, 3));
assertFalse(fog.isVisited(4, 3));
assertTrue(fog.isVisited(Geom.createArea(3, 3, 1, 1)));
assertEquals(0, count.get());
fog.setEnabled(false, false);
assertFalse(fog.isFogged(2, 3));
assertFalse(fog.isFogged(3, 3));
assertFalse(fog.isFogged(4, 3));
assertTrue(fog.isVisible(map.getTile(2, 3)));
assertTrue(fog.isVisible(map.getTile(3, 3)));
assertTrue(fog.isVisible(map.getTile(4, 3)));
assertTrue(fog.isVisited(2, 3));
assertTrue(fog.isVisited(3, 3));
assertTrue(fog.isVisited(4, 3));
assertTrue(fog.isVisited(Geom.createArea(3, 3, 1, 1)));
}
Aggregations