an example of AI code, complete with a slightly altered version of @griffpatch 's layer sorter for convenience (games with lots of sprites need this) It mimics the FNAF 1 style of AI. Things are explained in the sprite.