In this first video, I'll explain what this series of videos is about and what our first steps are!
Let's build a simple pac-man game...
Hi! Welcome to this series of videos on building a simple Pac-Man game in Python. This series of videos is perfect for students that just learned how to program in Python and are now ready to program something bigger than simple functions!
Just follow the lectures below!
Our first step in the code will be to model the map of the game.
The first function we implement finds the coordinates of the pacman in a given map.
Let us now properly test the find_pacman() function we just created.
Our next step is to actually move the pacman from one position to another.
Let's show the pacman game for the first time to the player. It's a very simplistic map, but that's how we start!
We now move the pacman according to the key that the user pressed.
Moving is not that simple. The pacman should only move if a valid key was pressed or if the new position is within the borders of the map. Let's check that.
We now check if we hit a wall of if we hit a ghost. The play() function is getting more and more complicated.
The pacman wins the game if it collects all the pills. Let's find a way to count all the pills in the map.
It is time for the main loop of the game: we get the key from the user, we move the pacman, we repeat!
We now let the user know when s/he won or lost the game. The complex return of the play() function starts to pay off.
The ghosts should move randomly in the map. How do we do it? We first find all the ghosts in the map, and then, randomly select a direction for them. In this video, you also see that copying and pasting code is really prone to errors!
The ghosts should also respect the rules of the game: they should not go through walls or eat the pills. Let us add those checks.
Our UI is very simplistic. Let's make use of some ASCII art and make the UI a little bit more attractive.
It seems we are done! Let's revisit the code and discuss about our main coding decisions one more time