A guard made with useStateMachine: it patrols between two posts, chases the hero when it sees him ahead, attacks when he is close, searches looking both ways when it loses him, and goes back to its post. Each state says what it does on the way in (onEnter, here its animation) and every frame (onUpdate), and changes with machine.go(). Arrow keys or A and D walk; stand behind the guard and it will not see you.
The guard is a piece made with useSpawn, and the machine is its own. The HUD reads it three ways: useWatch(fn, [machine]) for the state, machine.time every frame for how long it has been in it, and machine.onChange for the last change. The swing ends on the animation's onEnd, which sends the guard back to the chase.