Site hosted by Angelfire.com: Build your free website today!

Pacman

Source code for Pacman

After literally years of allowing my Pacman tutorial to rot on the internet I have made some progress. With a few hours of work I have made randomly generated mazes, made the mazes have a nice mirrored quality, similar to the real pacman, added pellets to eat, added a single not-so-smart ghost, and caused the maze to regenerate when you eat everything. Oddly, this only took a few hours of work. Maybe eight hours tops. Many thanks to my brother Matt who refactored some of the code "just for fun". However, don't blame him for the ugliness of this code. That is all my fault.

There are probably several ways to do random maze generation. The one I am using, I learned in Nick Parlante's CS193i class at Stanford. I probably implemented it better in for that project than I did here. Basically, you have a cell with 4 walls and an variable that holds whether it has been visited or not. You pick a cell to visit, mark it as visited, and randomly choose a neighbor cell to visit. If that neighbor cell hasn't been visited, get rid of your wall bording it and its wall bordering you. Then recusively visit the neighbor cell. This results in a maze in which there is only one path from one cell to any other

I have done all sorts of things to make the maze generation more complicated (and pacman-like) than that. I mirror the maze while it is being generated so that it is symmetrical. I also make each cell a block and each wall a block. Finally, I randomly remove some walls to open the maze up more. Otherwise it would be all dead ends. There are better ways to do these things. I just choose a quick and dirty way while I was writing it.

Many things left to do before the game is any good:
Smarter/different ghosts
Power-ups of some sort
Two speeds - slow for chomping, faster for squares that have already been cleared
Lots of graphical improvements are needed: maze is still boxy, ghost is a box as well

Finally, I have started to use Eclipse (well, ok WSAD, same thing) as my development environment instead of VisualAge for Java. Both Eclipse and VAJ are excellent tools. Note that the applet no longer runs if your Java is old. You can easily update it by downloading a new JRE at http://java.sun.com/.

Next: Day 7.