Search in sources :

Example 1 with HearingSenseComponent

use of com.almasb.fxgl.ai.senseai.HearingSenseComponent in project FXGL by AlmasB.

the class SenseAISample method spawnNPC.

private void spawnNPC(int x, int y) {
    var rect = new Rectangle(20, 20, FXGLMath.randomColor().brighter());
    rect.setStrokeType(StrokeType.INSIDE);
    rect.setStroke(Color.BLACK);
    var sense = new HearingSenseComponent(150);
    var text = getUIFactoryService().newText("", Color.WHITE, 16.0);
    text.textProperty().bind(sense.stateProperty().asString());
    var hearingRadiusCircle = new Circle(150);
    hearingRadiusCircle.setFill(null);
    hearingRadiusCircle.setStroke(Color.GREEN);
    var e = entityBuilder().type(Type.NPC).viewWithBBox(rect).view(text).view(hearingRadiusCircle).anchorFromCenter().with(new CellMoveComponent(CELL_WIDTH, CELL_HEIGHT, 150)).with(new AStarMoveComponent(grid)).with(sense).with(new CustomAIComponent()).buildAndAttach();
    e.getComponent(AStarMoveComponent.class).stopMovementAt(x, y);
}
Also used : Circle(javafx.scene.shape.Circle) CellMoveComponent(com.almasb.fxgl.pathfinding.CellMoveComponent) Rectangle(javafx.scene.shape.Rectangle) HearingSenseComponent(com.almasb.fxgl.ai.senseai.HearingSenseComponent) AStarMoveComponent(com.almasb.fxgl.pathfinding.astar.AStarMoveComponent)

Aggregations

HearingSenseComponent (com.almasb.fxgl.ai.senseai.HearingSenseComponent)1 CellMoveComponent (com.almasb.fxgl.pathfinding.CellMoveComponent)1 AStarMoveComponent (com.almasb.fxgl.pathfinding.astar.AStarMoveComponent)1 Circle (javafx.scene.shape.Circle)1 Rectangle (javafx.scene.shape.Rectangle)1