YOUR MISSION: Make the classic arcade game Pac-Man in Scratch

pacmanhighresscreenshot300

Starter Project for you to Re-mix:
You can remix this starter project: https://scratch.mit.edu/projects/171742807/
It contains Pac-Man graphics and sounds that you can use. There is some code to get you started with setting up the dots that Pac-Man can eat.

Pac-Man movement:
In the original Pac-Man game, the Pac-Man character keeps moving in a straight line even when you are not pressing using the pointing device (joystick, arrow keys, etc.). He only stops when he reaches a wall in front of him.

One approach to getting Pac-Man to move in straight lines inside the maze paths is to use a guide. In the starter project you will see a sprite called ‘maze guide’. Create a sprite that is just a single dot and program it so that it can move along the path in ‘maze guide’ but cannot move outside the path. Since this little dot will be guiding Pac-Man around the maze, let’s refer to it as Pacman guide.

Pacman guide will always move in some direction until he reaches a point where he can’t move any more in that direction. If he is going LEFT and you press the UP arrow he will not go up until he reaches one of the corners where there is a path in the up direction. So when you press UP he will just keep going left but remember that he has to go up when he reaches the next corner if there is an up path. So you will need 2 variables for his direction, one variable for the current direction and one variable for the next direction. When you are creating these variables, you should make them ‘For this sprite only’.

You can program the arrow keys to set the next direction variable:

When moving Pacman guide you can check that it is still on the path. If it goes off the path you need to move it back in the opposite direction until it is back on the path:

When Pacman guide reaches a corner (see ‘corner guide’ sprite in starter project) you can test if there is a path available in the direction of the next direction variable:

Ghost movement:
You can program the ghosts to give them Artificial Intelligence! Did you know that in the original Pac-Man game each ghost has it’s own unique behaviour!
Here is a detailed analysis of the ghost movement in Pac-Man:
http://gameinternals.com/post/2072558330/understanding-pac-man-ghost-behavior
The most important thing to note is that the ghosts have 3 different modes: Chase, Scatter, and Frightened. In Chase mode they are basically chasing after Pac-Man. In Scatter mode they go towards the corners (each ghost has it’s own corner). In Frightened mode they move away from Pac-Man (because Pac-Man can eat them!) and they move slower.

To get started with the ghost movement you can use the same code as Pac-man. You can have a guide dot for each ghost. The guide dot will need to stick to the path just like Pac-man’s guide dot so that part of the code will be the same. The thing that will be different is that the ghosts will not take input from the arrow keys to determine their next direction. Instead you will program the logic that determines their next directions. An easy way to start is just to make them go in random directions. Once you have that working you can then refine it and have them make decisions on which way to turn based on where Pac-man is. You can program the logic to implement the Chase, Scatter, and Frightened modes.

This project is based on the game Pac-Man, originally created by Toru Iwatani, copyright Namco, and is used here in the context of ‘fair use’ for educational purposes.