>Ok, I'll keep this short and succinct. I have a small 'maze' in my
>game. There is an NPC in the maze that is afraid of light. There are
>4 objects that can bring light to a room. and the player can move them
>around. There are no dead ends. What is a good way for the NPC to try
>and avoid being trapped between two light sources? It would be
>helpful if you would explain in simple language. I haven't had much
>experience with this sort of thing.
Uh-oh. You're in arcade-game territory now. Off the top of my head I'd
say you need to lay a notional grid across the maze and use a
coordinate system to regulate the NPC's movement, perhaps by evaluating
the movement of the just-moved light source as "towards" or "away from"
the NPC. Assign coordinates manually to each room of the maze and then
base your NPC's movement routine on increments and decrements to the
rows/columns (e.g. "if room_moved_to's coordinate_x > room_moved_from's
coordinate_x and room_moved_to's coordinate_y < room_moved_from's
coordinate_y then do such and such"). The actual logic for all this,
though, considering that you not only have to evaluate the moving
light, but also the positions of three others (that is, if you want
your NPC to appear at all smart), is way beyond my "off the top of my
head" ability. You might try asking around in the arcade-type game
programming newsgroups; someone there probably has existing code you
could peruse (or maybe GRees will pop up with a two-line solution for
you; I hope so).
Note: I've presumed above that the point of the whole exercise is for
the player to trap the NPC, since, if it's not, it would probably be
easier and more advisable simply to let the NPC cheat and hop to a
different part of the maze whenever the lights get too near. If the
player is not actively trying to trap the NPC, he/she probably won't
notice or care much.
Jim Newland
76461.2144@compuserve.com