finite state machine example from Programming Game AI By Example by Mat Buckland