Expanding on Pathfinding
With just under two weeks left to finish Pacman, I’m spending a bit more time on the game itself. Right now I actually have most of it done, including probably the most complex component which is the path finding. What I did today, besides getting collision detection and movement for the player as Pacman working, was making some changes to pathfinding.
There are four ghosts (not yet done), each that have their own individual route to the player. As the operation is fairly expensive, it’s calculated every two seconds. You can see in the picture that the red and yellow line meet somewhat behind the Pac-Man character, which was during a two second interval.
There are four coloured lines; red, white, yellow and green. While white is not actually visible in the above picture, it was drawn over by the red line, following the same path. The original game featured somewhat more intelligent AI, but for assessment purposes creating an illusion of intelligence is sufficient, which I’m doing here.
The method of this isn’t exactly the most efficient, as I’m simply checking which of the four paths it is each time I calculate, and depending on this path I disable every 10th, 25th or 30th node so that an alternative route is calculated, while still keeping the route relatively short.
My next task will be to add the ghosts and have them chasing a vector of positions that form a path. Then eventually when everything is working alright, I’ll make power pills do something more useful, maybe a cherry and some fancy 8-bit sounds.
One thing I’m worried about with pathfinding is that when the player transitions from the left or right side of the screen to the other end, which might confuse the ghosts into taking the long way around. Either way I don’t believe this is something I’m being marked on anyway.