
Pacmancode
This website is all about how to program a Pacman game in the Python language using Pygame. In order to get the most out of this site you need to progress through each "level" sequentially. The code in each level builds on the previous levels. In the end you'll have a …
Blank Screen - PACMANCODE
From your command line and from within the Pacman folder type the following to run the program: python run.py or python3 run.py If all is successful you should see a black window open up. If you get some errors then check your code and make sure all of your indentations are correct.
Vectors - PACMANCODE
You can organize the code any way you want, but for this tutorial I'm just going to have all of the code in a single folder called 'Pacman'. What I will then do is create this vector.py file inside the 'Pacman' folder and then copy the following code to the file.
Basic Movement - PACMANCODE
We will use the directional keys in order to move Pacman around. Pacman can only move around in one of four directions: up, down, left, and right. Pacman can only move in one of these directions at any one time, he does not move in a diagonal at any time.
Pacman Maze
All we're going to do is replace the small maze with an actual Pacman maze. This maze is the same as the one you'll find in the first Pacman game. It looks different because you're only seeing the nodes.
Nodes
I'll go over what I mean by a "map of connected nodes" below and we'll generate a simple maze for Pacman to traverse as we're learning the basics of this. Maybe you've studied data structures, but it's more than likely you haven't.
Animate Pacman
We need to define the Pacman animations by indicating where the images are in the spritesheet. In the PacmanSprites class we'll create two new methods. In one of the methods we'll define all of Pacman's possible animations.
Eating Pellets - PACMANCODE
In this section we'll convince Pacman that he needs to eat these pellets. Eating the pellets is really easy. During each Pacman update we just need to check if he has collided with any of the pellets.
node movement (Part 1) - PACMANCODE
Having a map of connected nodes is great, but now we have to teach Pacman how to move around the maze from node to node. The first type of movement we're going to teach him is simply jumping from node to node.
More Ghosts - PACMANCODE
It's better if we deal with the ghosts as a group rather than individually. It'll make it so we write less code which is always good. So we'll create a GhostGroup class in the ghosts.py file after all of the classes we just made. We're going to store all of the ghost objects in a list.