Search in sources :

Example 6 with EntityView

use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.

the class SaveSample method initGame.

private void initGame(Point2D playerPos, Point2D enemyPos) {
    playerPosition = playerPos;
    enemyPosition = enemyPos;
    player = new Entity();
    player.getTypeComponent().setValue(Type.PLAYER);
    player.getPositionComponent().setValue(playerPosition);
    player.getViewComponent().setView(new EntityView(new Rectangle(40, 40, Color.BLUE)));
    playerControl = new PlayerControl();
    player.addControl(playerControl);
    enemy = new Entity();
    enemy.getTypeComponent().setValue(Type.ENEMY);
    enemy.getPositionComponent().setValue(enemyPosition);
    enemy.getViewComponent().setView(new EntityView(new Rectangle(40, 40, Color.RED)));
    getGameWorld().addEntities(player, enemy);
}
Also used : Entity(com.almasb.fxgl.entity.Entity) EntityView(com.almasb.fxgl.entity.view.EntityView) Rectangle(javafx.scene.shape.Rectangle) PlayerControl(common.PlayerControl)

Example 7 with EntityView

use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.

the class GameScene method destroyView.

private void destroyView(ViewComponent viewComponent) {
    EntityView view = viewComponent.getView();
    removeGameView(view, viewComponent.getRenderLayer());
}
Also used : EntityView(com.almasb.fxgl.entity.view.EntityView)

Example 8 with EntityView

use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.

the class GameScene method initView.

private void initView(ViewComponent viewComponent) {
    EntityView view = viewComponent.getView();
    addGameView(view, viewComponent.getRenderLayer());
    viewComponent.renderLayerProperty().addListener((o, oldLayer, newLayer) -> {
        getRenderGroup(oldLayer).getChildren().remove(view);
        getRenderGroup(newLayer).getChildren().add(view);
    });
}
Also used : EntityView(com.almasb.fxgl.entity.view.EntityView)

Example 9 with EntityView

use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.

the class RangeTest method onUpdate.

@Override
protected void onUpdate(double tpf) {
    List<Entity> list = getGameWorld().getEntitiesInRange(player.getBoundingBoxComponent().range(40, 40));
    list.forEach(e -> {
        if (e == markers)
            return;
        EntityView view = e.getComponent(ViewComponent.class).getView();
        view.getNodes().stream().map(n -> (Rectangle) n).forEach(r -> r.setFill(Color.YELLOW));
    });
    List<Entity> list2 = getGameWorld().getEntitiesCopy();
    list2.removeAll(list);
    list2.forEach(e -> {
        EntityView view = e.getComponent(ViewComponent.class).getView();
        view.getNodes().stream().map(n -> (Rectangle) n).forEach(r -> r.setFill(Color.BLACK));
    });
}
Also used : KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) Control(com.almasb.fxgl.entity.Control) Input(com.almasb.fxgl.input.Input) Rectangle(javafx.scene.shape.Rectangle) GameSettings(com.almasb.fxgl.settings.GameSettings) UserAction(com.almasb.fxgl.input.UserAction) Required(com.almasb.fxgl.entity.component.Required) List(java.util.List) PositionComponent(com.almasb.fxgl.entity.component.PositionComponent) ViewComponent(com.almasb.fxgl.entity.component.ViewComponent) Entities(com.almasb.fxgl.entity.Entities) EntityView(com.almasb.fxgl.entity.view.EntityView) GameApplication(com.almasb.fxgl.app.GameApplication) Entity(com.almasb.fxgl.entity.Entity) Entity(com.almasb.fxgl.entity.Entity) EntityView(com.almasb.fxgl.entity.view.EntityView) ViewComponent(com.almasb.fxgl.entity.component.ViewComponent) Rectangle(javafx.scene.shape.Rectangle)

Example 10 with EntityView

use of com.almasb.fxgl.entity.view.EntityView in project FXGL by AlmasB.

the class RangeTest method initGame.

@Override
protected void initGame() {
    spawnEntity(100, 100);
    spawnEntity(500, 300);
    spawnEntity(300, 15);
    spawnEntity(400, 500);
    spawnEntity(500, 500);
    player = new Entity();
    player.getPositionComponent().setValue(400, 300);
    player.getViewComponent().setView(new EntityView(new Rectangle(40, 40)), true);
    playerControl = new PlayerControl();
    player.addControl(playerControl);
    markers = new Entity();
    EntityView view = new EntityView();
    view.addNode(getMarker(-40, 0));
    view.addNode(getMarker(40, 0));
    view.addNode(getMarker(0, -40));
    view.addNode(getMarker(0, 40));
    view.addNode(getMarker(-40, -40));
    view.addNode(getMarker(40, -40));
    view.addNode(getMarker(-40, 40));
    view.addNode(getMarker(40, 40));
    markers.getViewComponent().setView(view);
    markers.getPositionComponent().xProperty().bind(player.getPositionComponent().xProperty());
    markers.getPositionComponent().yProperty().bind(player.getPositionComponent().yProperty());
    getGameWorld().addEntities(player, markers);
}
Also used : Entity(com.almasb.fxgl.entity.Entity) EntityView(com.almasb.fxgl.entity.view.EntityView) Rectangle(javafx.scene.shape.Rectangle)

Aggregations

EntityView (com.almasb.fxgl.entity.view.EntityView)15 Rectangle (javafx.scene.shape.Rectangle)10 Entity (com.almasb.fxgl.entity.Entity)8 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)2 PositionComponent (com.almasb.fxgl.entity.component.PositionComponent)2 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)2 GameApplication (com.almasb.fxgl.app.GameApplication)1 Vec2 (com.almasb.fxgl.core.math.Vec2)1 Control (com.almasb.fxgl.entity.Control)1 Entities (com.almasb.fxgl.entity.Entities)1 RenderLayer (com.almasb.fxgl.entity.RenderLayer)1 Required (com.almasb.fxgl.entity.component.Required)1 ViewComponent (com.almasb.fxgl.entity.component.ViewComponent)1 OffscreenCleanControl (com.almasb.fxgl.entity.control.OffscreenCleanControl)1 ProjectileControl (com.almasb.fxgl.entity.control.ProjectileControl)1 Input (com.almasb.fxgl.input.Input)1 UserAction (com.almasb.fxgl.input.UserAction)1 HitBox (com.almasb.fxgl.physics.HitBox)1 FixtureDef (com.almasb.fxgl.physics.box2d.dynamics.FixtureDef)1 RevoluteJointDef (com.almasb.fxgl.physics.box2d.dynamics.joints.RevoluteJointDef)1