use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.
the class ProducerModelTest method testStop.
/**
* Test the stop production.
*/
@Test
void testStop() {
producer.setStepsSpeed(50.0);
final AtomicReference<Featurable> done = new AtomicReference<>();
final AtomicReference<Featurable> skip = new AtomicReference<>();
producer.addListener(UtilProducible.createProducerListener(skip, skip, done, skip));
producer.recycle();
final Featurable featurable = UtilProducible.createProducible(services);
producer.addToProductionQueue(featurable);
producer.addToProductionQueue(featurable);
producer.update(1.0);
assertTrue(producer.isProducing());
producer.stopProduction();
assertFalse(producer.iterator().hasNext());
assertFalse(producer.isProducing());
producer.update(1.0);
producer.update(1.0);
producer.update(1.0);
producer.update(1.0);
assertNull(done.get());
}
use of com.b3dgs.lionengine.game.feature.Featurable 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.Featurable in project lionengine by b3dgs.
the class WorldHelper method createSpawner.
@Override
protected Spawner createSpawner() {
return new Spawner() {
private Optional<Media> raster = Optional.empty();
@Override
public void setRaster(Media raster) {
this.raster = Optional.ofNullable(raster);
}
@Override
public Featurable spawn(Media media, double x, double y) {
final Featurable f = factory.create(media);
f.getFeature(Transformable.class).teleport(x, y);
f.ifIs(Rasterable.class, r -> raster.ifPresent(m -> r.setRaster(true, m, map.getTileHeight())));
handler.add(f);
return f;
}
};
}
use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.
the class ExtractorModelTest method testExtractor.
/**
* Test the extractor.
*/
@Test
void testExtractor() {
final Featurable object = new FeaturableModel(services, setup);
object.addFeature(new TransformableModel(services, setup));
final ExtractorModel extractor = new ExtractorModel(services, setup);
extractor.recycle();
extractor.setCapacity(6);
extractor.setExtractionSpeed(50.0);
extractor.setDropOffSpeed(100.0);
extractor.prepare(object);
final AtomicReference<String> goTo = new AtomicReference<>();
final AtomicReference<String> startExtract = new AtomicReference<>();
final AtomicReference<String> extracted = new AtomicReference<>();
final AtomicReference<String> carry = new AtomicReference<>();
final AtomicReference<String> startDrop = new AtomicReference<>();
final AtomicReference<String> endDrop = new AtomicReference<>();
extractor.addListener(UtilExtractable.createListener(goTo, startExtract, extracted, carry, startDrop, endDrop));
assertNull(extractor.getResourceLocation());
assertNull(extractor.getResourceType());
extractor.setResource("wood", 1, 2, 1, 1);
final Tiled location = extractor.getResourceLocation();
assertEquals(1.0, location.getInTileX());
assertEquals(2.0, location.getInTileY());
assertEquals(1.0, location.getInTileWidth());
assertEquals(1.0, location.getInTileHeight());
assertEquals("wood", extractor.getResourceType());
assertFalse(extractor.isExtracting());
extractor.startExtraction();
assertFalse(extractor.isExtracting());
assertEquals("wood", goTo.get());
extractor.update(1.0);
assertTrue(extractor.isExtracting());
assertEquals("wood", startExtract.get());
assertNotEquals("wood", extracted.get());
extractor.update(1.0);
assertTrue(extractor.isExtracting());
assertEquals("wood", extracted.get());
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
assertTrue(extractor.isExtracting());
assertEquals("wood", carry.get());
extractor.update(1.0);
assertFalse(extractor.isExtracting());
assertEquals("wood", startDrop.get());
extractor.update(1.0);
extractor.update(1.0);
extractor.update(1.0);
assertTrue(extractor.isExtracting());
assertEquals("wood", endDrop.get());
object.getFeature(Identifiable.class).notifyDestroyed();
}
use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.
the class ExtractableModelTest method testConfigWithNode.
/**
* Test the extraction config with node.
*/
@Test
void testConfigWithNode() {
final MapTile map = new MapTileGame();
map.create(16, 16, 4, 4);
services.add(map);
final Featurable featurable = new FeaturableModel(services, setup);
featurable.addFeatureAndGet(new TransformableModel(services, setup)).teleport(16, 32);
final Media media = UtilExtractable.createMedia();
final Extractable extractable = new ExtractableModel(services, new Setup(media));
extractable.prepare(featurable);
assertEquals(10, extractable.getResourceQuantity());
assertEquals("gold", extractable.getResourceType());
assertEquals(1, extractable.getInTileX());
assertEquals(2, extractable.getInTileY());
assertEquals(1, extractable.getInTileWidth());
assertEquals(2, extractable.getInTileHeight());
extractable.getFeature(Identifiable.class).notifyDestroyed();
assertTrue(media.getFile().delete());
}
Aggregations