PACMANCODE

PACMANCODEPACMANCODEPACMANCODE
  • Home
  • Start
    • Vectors
    • Stacks
    • Blank Screen
    • Basic Movement
  • Level 1
    • Nodes
    • Node Movement (Part 1)
    • Node Movement (Part 2)
    • Node Movement (Part 3)
  • Level 2
    • Maze Basics
    • Pacman Maze
    • Portals
    • Pellets
    • Eating Pellets
  • Level 3
    • Ghosts Intro
    • Ghost Setup
    • Ghost AI
    • Modes
    • Ghost Home
    • Freight Mode
    • Spawn Mode
  • Level 4
    • More Ghosts
    • Start Positions
    • Fruit
    • Pausing
    • Level Advancing
    • Death to Pacman
    • Node Restrictions
  • Level 5
    • Text
    • Sprites
    • Life Icons
    • Graphical Mazes
    • Graphical Mazes Part 2
    • Animate Pacman
    • Animate Ghosts
  • Final
    • Pacman Death
    • Level Flash
    • More Fruit
    • More Mazes
    • The End
  • Contact
  • More
    • Home
    • Start
      • Vectors
      • Stacks
      • Blank Screen
      • Basic Movement
    • Level 1
      • Nodes
      • Node Movement (Part 1)
      • Node Movement (Part 2)
      • Node Movement (Part 3)
    • Level 2
      • Maze Basics
      • Pacman Maze
      • Portals
      • Pellets
      • Eating Pellets
    • Level 3
      • Ghosts Intro
      • Ghost Setup
      • Ghost AI
      • Modes
      • Ghost Home
      • Freight Mode
      • Spawn Mode
    • Level 4
      • More Ghosts
      • Start Positions
      • Fruit
      • Pausing
      • Level Advancing
      • Death to Pacman
      • Node Restrictions
    • Level 5
      • Text
      • Sprites
      • Life Icons
      • Graphical Mazes
      • Graphical Mazes Part 2
      • Animate Pacman
      • Animate Ghosts
    • Final
      • Pacman Death
      • Level Flash
      • More Fruit
      • More Mazes
      • The End
    • Contact

PACMANCODE

PACMANCODEPACMANCODEPACMANCODE
  • Home
  • Start
  • Level 1
  • Level 2
  • Level 3
  • Level 4
  • Level 5
  • Final
  • Contact

Pacmancode

PacmancodePacmancodePacmancode

Pacmancode

PacmancodePacmancodePacmancode

Welcome

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 complete Pacman game.

UPDATES

24 AUGUST 2021

Made some major updates.  I apologize if you're in the middle of the site at this time.  I pretty much rewrote the whole code, but I feel the updated code is much better and easier to understand.  If you are in the middle of this, then you'll have to start from the beginning again.  I know that will deter some of you from finishing, but think of it this way.  At least the second time around you should understand everything better right?  If it makes you feel better I've started this from scratch at least a dozen times.  Here are some of the changes that I made:


  • I reorganized the spritesheet so that it removes unused images.  
  • I removed the hash method in the vector class since I only had that for one thing and that one thing was removed as well.  Don't worry about what that one thing was, it's gone now.  
  • As much as it hurts me, I removed the stack file as well.  You don't need to use stacks, but I kept the page there in case you need to use stacks somewhere.  
  • I rewrote the node finding algorithm.  Oh man, was it ever confusing before!  What was I thinking?  This new algorithm makes much more sense and is a lot shorter.
  • Added some more spritesheets at the end if you want to do some sprite swaps.  It's easy to make your own as well.  
  • Added sections and removed sections.  
  • Removed the code files you would find at the bottom of each page.  It was just too much work on my end.  If I changed just one ittie bittie thing early on, then I would have to update all of the zip files from that point on with that one tiny change.  You'll just have to go through each section and write the code yourself.  I kept the one at the bottom of this page though since that shows the full code.  It's easier to update that than 3 dozen other ones.

If you're new to this site, then you'll want to start your Pacman journey with the "Start" tab above where you'll learn some basics like Vectors and Stacks.  You'll then want to progress through each section sequentially.  Don't skip any sections because you'll miss important code and your game will break.  Each section depends on the previous section.


I understand that this isn't the best or most efficient code in the world.  You'll probably scoff at my feeble attempt at programming and come up with a million better ways of doing things.  That's fine, you can always drop me a line and brag how much better you are than me, I don't mind because it's probably true.  If you do, just explain it in detail because I'd like to be a better programmer.  


If you get any errors, then make sure that your tabs are correct since Python is a tabbed language.  If you've double checked any spelling mistakes and are still getting errors, then let me know and I'll check it out.  I've personally gone through this site many times checking for things that would cause errors, but it's possible to still miss something.


Also, if you feel that any sections are too long or boring and need more explaining or more pictures, then let me know and I'll try and figure out a better way to present the information.  


Most of all, enjoy the site for what it is and I just hope you learn something.  

Sections

Start

Level 1

Level 1

Here we create a Vector class, open a basic window, and move a character around the screen.

Level 1

Level 1

Level 1

In this level we create a blank screen and make a basic Pacman object that can move around the screen.

Level 2

Level 1

Level 2

Here we talk about Nodes and restrict Pacman's movement so that he can only move between these Nodes.

Level 3

Level 3

Level 2

We add the Ghost enemies and create their AI.  We start with a single Ghost then expand from there.

Level 4

Level 3

Level 4

We kind of tie it all together before making it look good.

Level 5

Level 3

Level 4

We add text, sprites, and animations.

Final

Final

Final

We add some finishing touches like more mazes.

Photo Gallery

    Complete Code

    For those of you who are interested in having the complete code, here it is.  Just download the file below and unzip it.  This game was written with Python 3 in mind, so ensure you have Python 3 installed.  It will work in Python 2.7 as well, but that may not be the case in future updates.


    Assuming you have Python 3 installed as your default Python:  To play the game open up a terminal and type 'python run.py'.  When the screen opens up press the 'spacebar' to start the game.  You can also use the spacebar to pause and un-pause the game.  When playing the game, use the directional keys to move Pacman up, down, left, and right.


    I of course would still suggest that you go through the site and write the game yourself, but this should allow you to know where any errors have occurred since you'll have a working version.  Also maybe playing the game will give you the desire to figure out how it works.


    You can change the size of the screen by modifying the TILEWIDTH and TILEHEIGHT variables in the constants.py file.  Things work best if you keep those values the same like 16x16 or 34x34 instead of something like 16x32.  It will still work, it will just look weird.


    *You will also need to make sure that Numpy is installed since some of the code depends on Numpy.  I really only use Numpy for a few things, but they do make those few things easier to do.

    Pacman_Complete (zip)Download

    Copyright © 2022 Pacmancode - All Rights Reserved.


    Powered by GoDaddy Website Builder