This week is time for a throwback arcade twist 'em up

 

Pac 3: Spooky's Revenge

 

The conceit behind Pac 3 is "Pac-Man but you control the ghosts". I don't remember where that idea originated from but I was immediately enthralled with the idea, plus this gave me a good chance to work with an A* pathfinding package I had lying around but have never applied to a game before. The name Pac 3 comes from the obscure trivia fact that there was indeed a Pac-Man 2 - a bizarre graphical adventure game where you control pac-man's emotions, and I like to think of this as the sequel that game. 

Click here to play Pac 3: Spooky's Revenge

 

 

The Good

I like how this one turned out, and may someday return to it in earnest to add even more. This project leans on the technical side a lot more than the design. Unlike previous weeks where I put off all work until the weekend, I stayed up until 3-4 most mornings just to keep working on the programming. I didn't code the A* algorithm myself, but I found a pretty good implementation online which I just had to make a few changes to get functioning properly. Instead the big work for me this week was AI - specifically making the pacman character move somewhat intelligently.

To that end I ended up with two different pathfinding algorithms - the first one finds the nearest cell with a pellet that hasn't been eaten yet and avoid the ghost character. The second happens when the pacman eats a power pellet and he beelines towards the player. However the first error I encountered is that ghost would always target the spot the ghost was initially at, even when the ghost moves. So I made it poll every time it reaches a new grid space to find the player - and the game's performance tanked. So through some optimization I got it working at a much more efficient pace. This is visible in the game that pacman will chase down the ghost after eating a power pellet and move to the most efficient path as both he and the ghost moves around. I could also have it pick a random path as well (that avoids the ghost) but decided not too since that was a bit too stupid.

I managed to find a bunch of the sound effects and sprites that I put in there that really give it a nice pac-man touch. Especially the little intro music with the yellow "Ready!" text. I initially was thinking it was better to find or make creative commons images, but I'm pretty sure this isn't going to attract the attention of Namco's lawyers anytime soon. If Namco's lawyers are reading this, we should cut a deal where I work this game even more and you release as an official Pac-Man game.

The Bad

The initial plan was much more ambitious. I wanted to have all 4 ghosts on the field auto-moving around, with the player either controlling one at a time or by setting 'turn points' where the next ghost to cross it would turn. However because of time I scrapped all that and just had the player control the ghost directly. This is better for the game as it is, but disappointing that you essentially are just a different looking pacman in terms of game feel. Although the excitement from having to run away from pacman when he eats a power pellet is palpable.

I also found out the biggest game-breaking problem when playing as the ghosts: All the player needs to do is cut off pacman from reaching one pellet by sitting on it and not moving. I implemented one solution: making the ghost fade out and eventually die without movement. It works to get the player moving but I'd have liked to experiment with more options because I feel like there is something that could have been more elegant. I also made the power pellet timer last long enough that pacman can pretty much always reach the player if they are camping.

There is a few bugs still left in the game. While they are not critical bugs, it sucks to leave them in there but I had to cut the ropes at some point. The first one is that occasionally when pacman goes through the screen wrap point, his pathing gets screwed up out the other end and he gets stuck trying to bury himself inside a wall. It's rare but noticeable. The other major bug is something with the audio when pacman eats a power pellet. It seems like the ambient sound effect plays like 10 times when turns corners which sounds bad but no so awful I felt compelled to remove the sound altogether.

Also, the reason pacman is simply a circle and not a fully animating sprite is not because I couldn't do it, but because that would take a long time to implement correctly. I'd have to calculate the cardinal direction from the previous direction and choose the correct facing sprite animation. That isn't hard, just time-consuming. I also got used to the sphere and kinda like it.

The Lesson

I didn't really learn about A* since I didn't write the actual pathfinding algorithm, however I did implement A* to make real AI for pacman, which I've never done before. Now that I've dipped my toes in to AI, I can start practicing more with it in the future.