Search in sources :

Example 21 with Featurable

use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.

the class Hud method clearMenus.

/**
 * Clear current menus.
 */
private void clearMenus() {
    for (final Featurable menu : menus) {
        menu.getFeature(Identifiable.class).destroy();
        handler.remove(menu);
    }
    menus.clear();
}
Also used : Featurable(com.b3dgs.lionengine.game.feature.Featurable) Identifiable(com.b3dgs.lionengine.game.feature.Identifiable)

Example 22 with Featurable

use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.

the class Scene method load.

@Override
public void load() {
    map.create(Medias.create("level.png"));
    camera.setView(0, 0, getWidth(), getHeight(), getHeight());
    camera.setLocation(160, 96);
    map.create(Medias.create("level.png"));
    map.addFeature(new MapTileViewerModel(services));
    map.addFeatureAndGet(new MapTileGroupModel()).loadGroups(Medias.create("groups.xml"));
    map.addFeatureAndGet(new MapTilePathModel()).loadPathfinding(Medias.create("pathfinding.xml"));
    camera.setLimits(map);
    handler.add(map);
    final Featurable peon1 = factory.create(Peon.MEDIA);
    peon1.getFeature(Pathfindable.class).setLocation(20, 16);
    peon1.getFeature(Pathfindable.class).setDestination(23, 12);
    peon1.getFeature(Pathfindable.class).pointTo(1, 2);
    handler.add(peon1);
    peon2 = factory.create(Peon.MEDIA);
    peon2.getFeature(Pathfindable.class).setLocation(22, 8);
    handler.add(peon2);
    final Featurable peon3 = factory.create(Peon.MEDIA);
    peon3.getFeature(Pathfindable.class).setLocation(25, 10);
    assertTrue(peon3.getFeature(Pathfindable.class).isPathAvailable(23, 12));
    peon3.getFeature(Pathfindable.class).setDestination(23, 12);
    handler.add(peon3);
    peon2.getFeature(Pathfindable.class).setIgnoreId(peon3.getFeature(Identifiable.class).getId(), true);
    peon2.getFeature(Pathfindable.class).pointTo(map.getTile(25, 25));
    assertEquals(Orientation.NORTH_EAST, peon2.getFeature(Pathfindable.class).getOrientation());
    peon2.getFeature(Pathfindable.class).setOrientation(Orientation.NORTH_WEST);
    assertEquals(Orientation.NORTH_WEST, peon2.getFeature(Pathfindable.class).getOrientation());
    peon2.getFeature(Pathfindable.class).addListener(listener);
    tick.start();
}
Also used : MapTilePathModel(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.MapTilePathModel) Pathfindable(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) MapTileViewerModel(com.b3dgs.lionengine.game.feature.tile.map.viewer.MapTileViewerModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 23 with Featurable

use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.

the class Scene method load.

@Override
public void load() {
    map.create(Medias.create("forest.png"));
    final MapTileGroup mapGroup = map.addFeatureAndGet(new MapTileGroupModel());
    final MapTilePath mapPath = map.addFeatureAndGet(new MapTilePathModel());
    camera.setView(VIEW_X, VIEW_Y, getWidth() - VIEW_X, getHeight() - VIEW_Y, getHeight());
    camera.setLimits(map);
    camera.setLocation(160, 96);
    map.addFeature(new MapTileViewerModel(services));
    handler.add(map);
    mapGroup.loadGroups(Medias.create("groups.xml"));
    mapPath.loadPathfinding(Medias.create("pathfinding.xml"));
    cursor.addImage(0, Medias.create("cursor.png"));
    cursor.addImage(1, Medias.create("cursor_order.png"));
    cursor.load();
    cursor.setGrid(map.getTileWidth(), map.getTileHeight());
    cursor.setSync(mouse);
    cursor.setViewer(camera);
    final Factory factory = services.create(Factory.class);
    final Media media = Medias.create("Hud.xml");
    final Hud hud = factory.create(media);
    handler.add(hud);
    final Selector selector = services.get(Selector.class);
    selector.addFeatureAndGet(new LayerableModel(4));
    selector.setClickableArea(camera);
    selector.setSelectionColor(ColorRgba.GREEN);
    selector.setClickSelection(MouseAwt.LEFT);
    final Featurable peon = factory.create(Medias.create("Peon.xml"));
    peon.getFeature(Pathfindable.class).setLocation(20, 10);
    handler.add(peon);
    transformable = peon.getFeature(Transformable.class);
    tick.start();
}
Also used : Media(com.b3dgs.lionengine.Media) Factory(com.b3dgs.lionengine.game.feature.Factory) Transformable(com.b3dgs.lionengine.game.feature.Transformable) LayerableModel(com.b3dgs.lionengine.game.feature.LayerableModel) MapTilePath(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.MapTilePath) MapTilePathModel(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.MapTilePathModel) Pathfindable(com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable) MapTileGroup(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroup) Hud(com.b3dgs.lionengine.game.feature.collidable.selector.Hud) MapTileGroupModel(com.b3dgs.lionengine.game.feature.tile.map.MapTileGroupModel) MapTileViewerModel(com.b3dgs.lionengine.game.feature.tile.map.viewer.MapTileViewerModel) Featurable(com.b3dgs.lionengine.game.feature.Featurable) Selector(com.b3dgs.lionengine.game.feature.collidable.selector.Selector)

Example 24 with Featurable

use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.

the class FovableModelTest method testFovable.

/**
 * Test the fovable model.
 */
@Test
void testFovable() {
    final MapTile map = UtilMap.createMap(7);
    services.add(map);
    final Setup setup = new Setup(config);
    final Fovable fovable = new FovableModel(services, setup);
    final Featurable featurable = new FeaturableModel(services, setup);
    final Transformable transformable = featurable.addFeatureAndGet(new TransformableModel(services, setup));
    transformable.teleport(1, 2);
    transformable.setSize(3, 4);
    fovable.prepare(featurable);
    fovable.setFov(5);
    assertEquals(1, fovable.getInTileX());
    assertEquals(2, fovable.getInTileY());
    assertEquals(3, fovable.getInTileWidth());
    assertEquals(4, fovable.getInTileHeight());
    assertEquals(5, fovable.getInTileFov());
    assertTrue(fovable.canUpdate());
    fovable.setCanUpdate(() -> false);
    assertFalse(fovable.canUpdate());
}
Also used : TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Transformable(com.b3dgs.lionengine.game.feature.Transformable) UtilTransformable(com.b3dgs.lionengine.game.feature.UtilTransformable) 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) Test(org.junit.jupiter.api.Test)

Example 25 with Featurable

use of com.b3dgs.lionengine.game.feature.Featurable in project lionengine by b3dgs.

the class ComponentNetwork method handleIdentifiableGet.

private void handleIdentifiableGet(Packet packet) {
    final int dataId = packet.getDataId();
    final Integer dataIdKey = Integer.valueOf(dataId);
    final Featurable featurable = handler.get(dataIdKey);
    if (featurable != null && !containsPending(packet.getClientSourceId(), dataIdKey)) {
        if (server != null) {
            send(new IdentifiableCreate(UtilNetwork.SERVER_ID, packet.getClientSourceId(), dataId, featurable.getMedia()), packet.getClientId());
        } else if (client != null) {
            send(new IdentifiableCreate(client.getClientId(), packet.getClientSourceId(), dataId, featurable.getMedia()));
        }
    }
}
Also used : Featurable(com.b3dgs.lionengine.game.feature.Featurable)

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