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);
}
Aggregations