use of com.almasb.fxgl.dsl.components.FollowComponent in project FXGL by AlmasB.
the class EntityActionSample method initGame.
@Override
protected void initGame() {
getGameScene().setBackgroundColor(Color.LIGHTGRAY);
mover = entityBuilder().at(400, 20).viewWithBBox(texture("player2rot.png").multiplyColor(Color.RED)).with(new ProjectileComponent(new Point2D(0, 1), 200)).onClick(e -> {
entity.getComponent(ActionComponent.class).addAction(new FollowAction(mover));
}).buildAndAttach();
mover2 = entityBuilder().at(500, 200).viewWithBBox(texture("player2rot.png").multiplyColor(Color.BLUE)).with(new ProjectileComponent(new Point2D(1, 0), 250)).onClick(e -> {
entity.getComponent(ActionComponent.class).addAction(new FollowAction(mover2));
}).buildAndAttach();
entity = entityBuilder().at(400, 300).viewWithBBox("player2rot.png").with(new ActionComponent()).with(new FollowComponent(null, 150, 40, 100)).with(new FixRotateComponent()).buildAndAttach();
unit = entityBuilder().at(700, 400).viewWithBBox(new Rectangle(40, 40, Color.GREEN)).with(new FollowComponent(null, 100, 30, 50)).onClick(e -> {
entity.getComponent(ActionComponent.class).addAction(new RecruitAction(unit));
}).buildAndAttach();
// unit2 = entityBuilder()
// .at(700, 200)
// .view(new Rectangle(40, 40, Color.GREEN))
// .with(new FollowComponent(null, 50, 60, 130))
// .onClick(() -> {
// entity.getComponent(ActionComponent.class)
// .addAction(new RecruitAction(unit2));
// })
// .buildAndAttach();
}
use of com.almasb.fxgl.dsl.components.FollowComponent in project FXGL by AlmasB.
the class PlatformerSample method initGame.
@Override
protected void initGame() {
var controllerService = getService(ControllerInputService.class);
controllerService.getGameControllers().forEach(con -> con.addInputHandler(getInput()));
entityBuilder().buildScreenBoundsAndAttach(40);
createPlatforms();
player = createPlayer(100, 100, 40, 60);
player.getTransformComponent().setScaleOrigin(new Point2D(20, 30));
player.getComponent(PhysicsComponent.class).onGroundProperty().addListener((o, oldValue, newValue) -> {
System.out.println(newValue ? "On Ground" : "In the air");
});
entityBuilder().at(300, 150).view(new Circle(25, Color.RED)).with(new FollowComponent(player, 150, 50, 60).setMoveDelay(Duration.seconds(2))).buildAndAttach();
}
Aggregations