Seeking Brains In a 2D Plane
I started back up on my zombie game the other day, with the approach of ditching the attempt at fancy graphics, and focusing on building a minimalistic but playable game. Since I needed to rebuild it with XNA 2.0 anyways, I started over with a great 2D tile engine from Nick Gravelyn. I then abstracted out the NPC classes a bit, and started by making a zombie NPC. Of course a zombie must seek brains, but how exactly would that work?
Zombies are too stupid to use a “real” pathfinding algorithm like A*, but a simple x,y comparison leads to an ugly behavior where it walks the diagonal first, then a straight line the rest of the way. I ended up finding the perfect algorithm in a line-of-sight demonstration for roguelikes, using Bresenham’s line algorithm. This algorithm is perfect for zombies, because they’ll travel in a straight line to food, until they hit an obstacle, then stop until the obstacle is gone. I’ll also be able to reuse this algorithm for my line-of-sight, line-of-smell, and line-of-sound algorithms to determine a zombie’s prefered target for tender, delicious brains.
