use of common.PlayerControl in project FXGL by AlmasB.
the class EventsSample 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();
getGameWorld().addEntities(player, enemy);
// 1. add event trigger and specify when and what to fire
// you can use a custom event or pre-defined event / with custom event type
getEventBus().addEventTrigger(new EventTrigger<EntityEvent>(() -> player.getRightX() > enemy.getX(), () -> new EntityEvent(Events.PASSED, player, enemy)));
// 2. add event handler using code OR
getEventBus().addEventHandler(MyGameEvent.ANY, event -> {
System.out.println("Code handler: " + event);
});
getMasterTimer().runOnceAfter(() -> getEventBus().fireEvent(new MyGameEvent(MyGameEvent.LOW_HP)), Duration.seconds(1));
}
Aggregations