Smart Sprites: path, vision and prediction
Enemies that find the way through mazes, see you and predict your moves.
- walk 2 steps along the path to Player: finds the shortest route (A* algorithm) avoiding solid map blocks and barriers. Use inside a "forever".
- can I see Player within 200 steps (60 degree view)?: true if near, inside the vision cone and with no wall in between. Use 360 degrees to see all around.
- predict x of Player in 1 sec.: where it will be. Aim at that point to intercept.
- flee from, wander and patrol between two points give ready-made behaviors.
- … of the nearest X and number of X (with clones) count clones.
Ghost recipe: if it can see the player, it runs along the path; otherwise it walks slowly. See Ghost Maze and Space Hunt.