Search in sources :

Example 1 with PlayerControl

use of common.PlayerControl in project FXGL by AlmasB.

the class PhysicsSample method initGame.

@Override
protected void initGame() {
    playerControl = new PlayerControl();
    player = Entities.builder().type(Type.PLAYER).at(100, 100).bbox(new HitBox("PLAYER_BODY", BoundingShape.box(40, 40))).viewFromNode(new Rectangle(40, 40, Color.BLUE)).with(playerControl).build();
    enemy = Entities.builder().type(Type.ENEMY).at(200, 100).viewFromNodeWithBBox(new Rectangle(40, 40, Color.RED)).build();
    // 2. we need to add Collidable component and set its value to true
    // so that collision system can 'see' our entities
    player.addComponent(new CollidableComponent(true));
    enemy.addComponent(new CollidableComponent(true));
    getGameWorld().addEntities(player, enemy);
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle) PlayerControl(common.PlayerControl)

Example 2 with PlayerControl

use of common.PlayerControl in project FXGL by AlmasB.

the class PhysicsSample2 method initGame.

@Override
protected void initGame() {
    playerControl = new PlayerControl();
    player = Entities.builder().type(Type.PLAYER).at(100, 100).bbox(new HitBox("PLAYER_BODY", BoundingShape.box(250, 40))).viewFromNode(new Rectangle(250, 40, Color.BLUE)).with(playerControl).build();
    enemy = Entities.builder().type(Type.ENEMY).at(200, 100).viewFromNodeWithBBox(new Rectangle(40, 40, Color.RED)).build();
    // 2. we need to add Collidable component and set its value to true
    // so that collision system can 'see' our entities
    player.addComponent(new CollidableComponent(true));
    enemy.addComponent(new CollidableComponent(true));
    getGameWorld().addEntities(player, enemy);
}
Also used : HitBox(com.almasb.fxgl.physics.HitBox) CollidableComponent(com.almasb.fxgl.entity.component.CollidableComponent) Rectangle(javafx.scene.shape.Rectangle) PlayerControl(common.PlayerControl)

Example 3 with PlayerControl

use of common.PlayerControl 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 4 with PlayerControl

use of common.PlayerControl in project FXGL by AlmasB.

the class AchievementsSample method initGame.

@Override
protected void initGame() {
    playerControl = new PlayerControl();
    Entity player = Entities.builder().at(100, 100).viewFromNode(new Rectangle(40, 40)).with(playerControl).buildAndAttach(getGameWorld());
    getGameState().doubleProperty("playerX").bind(player.getPositionComponent().xProperty());
}
Also used : Entity(com.almasb.fxgl.entity.Entity) Rectangle(javafx.scene.shape.Rectangle) PlayerControl(common.PlayerControl)

Example 5 with PlayerControl

use of common.PlayerControl in project FXGL by AlmasB.

the class BehaviorSample method initGame.

@Override
protected void initGame() {
    player = Entities.builder().at(100, 100).viewFromNode(new Rectangle(40, 40)).with(new PlayerControl()).buildAndAttach(getGameWorld());
    playerControl = player.getControl(PlayerControl.class);
    Entities.builder().at(400, 100).viewFromNode(new Rectangle(40, 40, Color.RED)).with(new AIControl("patrol.tree")).buildAndAttach(getGameWorld());
    Entities.builder().at(600, 100).viewFromNode(new Rectangle(40, 40, Color.LIGHTGOLDENRODYELLOW)).with(new AIControl("patrol.tree")).buildAndAttach(getGameWorld());
}
Also used : AIControl(com.almasb.fxgl.ai.AIControl) Rectangle(javafx.scene.shape.Rectangle) PlayerControl(common.PlayerControl)

Aggregations

PlayerControl (common.PlayerControl)6 Rectangle (javafx.scene.shape.Rectangle)6 HitBox (com.almasb.fxgl.physics.HitBox)3 Entity (com.almasb.fxgl.entity.Entity)2 CollidableComponent (com.almasb.fxgl.entity.component.CollidableComponent)2 AIControl (com.almasb.fxgl.ai.AIControl)1 EntityEvent (com.almasb.fxgl.entity.EntityEvent)1 EntityView (com.almasb.fxgl.entity.view.EntityView)1