Search in sources :

Example 16 with Featurable

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());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Test(org.junit.jupiter.api.Test)

Example 17 with Featurable

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);
}
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 18 with 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;
        }
    };
}
Also used : Rasterable(com.b3dgs.lionengine.game.feature.rasterable.Rasterable) MapTilePersister(com.b3dgs.lionengine.game.feature.tile.map.persister.MapTilePersister) SourceResolutionProvider(com.b3dgs.lionengine.graphic.engine.SourceResolutionProvider) Transformable(com.b3dgs.lionengine.game.feature.Transformable) IOException(java.io.IOException) CameraTracker(com.b3dgs.lionengine.game.feature.CameraTracker) FileReading(com.b3dgs.lionengine.io.FileReading) HandlerPersister(com.b3dgs.lionengine.game.feature.HandlerPersister) Services(com.b3dgs.lionengine.game.feature.Services) WorldGame(com.b3dgs.lionengine.game.feature.WorldGame) Spawner(com.b3dgs.lionengine.game.feature.Spawner) Media(com.b3dgs.lionengine.Media) Optional(java.util.Optional) ComponentCollision(com.b3dgs.lionengine.game.feature.collidable.ComponentCollision) FileWriting(com.b3dgs.lionengine.io.FileWriting) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Optional(java.util.Optional) Media(com.b3dgs.lionengine.Media) Transformable(com.b3dgs.lionengine.game.feature.Transformable) Spawner(com.b3dgs.lionengine.game.feature.Spawner) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 19 with Featurable

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();
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Tiled(com.b3dgs.lionengine.game.Tiled) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.jupiter.api.Test)

Example 20 with Featurable

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());
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) MapTileGame(com.b3dgs.lionengine.game.feature.tile.map.MapTileGame) Media(com.b3dgs.lionengine.Media) FeaturableModel(com.b3dgs.lionengine.game.feature.FeaturableModel) Setup(com.b3dgs.lionengine.game.feature.Setup) MapTile(com.b3dgs.lionengine.game.feature.tile.map.MapTile) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable) Test(org.junit.jupiter.api.Test)

Aggregations

Featurable (com.b3dgs.lionengine.game.feature.Featurable)35 Test (org.junit.jupiter.api.Test)19 FeaturableModel (com.b3dgs.lionengine.game.feature.FeaturableModel)18 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Setup (com.b3dgs.lionengine.game.feature.Setup)8 Media (com.b3dgs.lionengine.Media)7 Identifiable (com.b3dgs.lionengine.game.feature.Identifiable)6 Transformable (com.b3dgs.lionengine.game.feature.Transformable)5 Services (com.b3dgs.lionengine.game.feature.Services)4 MapTileGame (com.b3dgs.lionengine.game.feature.tile.map.MapTileGame)4 Animation (com.b3dgs.lionengine.Animation)3 Medias (com.b3dgs.lionengine.Medias)2 ViewerMock (com.b3dgs.lionengine.ViewerMock)2 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)2 Camera (com.b3dgs.lionengine.game.feature.Camera)2 IdentifiableModel (com.b3dgs.lionengine.game.feature.IdentifiableModel)2 LayerableModel (com.b3dgs.lionengine.game.feature.LayerableModel)2 MirrorableModel (com.b3dgs.lionengine.game.feature.MirrorableModel)2 UtilSetup (com.b3dgs.lionengine.game.feature.UtilSetup)2