OUR EXPERT
Calvin Robinson is a former assistant principal and computer science teacher with a degree in computer games design and programming.
Pac-Man is arguably one of the most famous video game characters in the world. First shooting to fame in 1980 with the release of remakes and sequels over the years, but nothing compares to the original.
It’s a simple premise, really. Pac-Man is a yellow, disk-shaped, mainly feature-less character, who roams around a 2D environment collecting dots. The player has to collect all the dots in the room without being touched by any of the four enemy characters in the form of ghosts. Pinky, Blinky, Inky and Clyde are brightly coloured to stand out against the black background, being pink, red, cyan and orange, respectively. Pac-Man must avoid the ghosts and collect all the dots to progress to the next level.
Pac-Man can only move up, down, left or right, through the maze of dots, but does have some advantages in his arsenal. By collecting large ‘power pellets’ Pac-Mac becomes energised and the ghosts all turn blue, enabling him to eat them on impact. The more blue ghosts you eat, the more points you get. As with all arcade games, the aim of the game is to get the highest score on the leader board.
Originally called Puck Man in Japan because of the main character looking like a hockey puck, Pac-Man was renamed for Western audiences to avoid any dodgy naming issues. It’s fun and friendly, and potentially the first ‘inclusive’ video game, what with Pac-Man being designed to appeal to girls as well as boys, and to attract a younger audience.
QUICK TIP
Speed up Pac-Man by increasing or decreasing the ‘onkey’ values, at the bottom of our code (x, y). Remember that positive numbers move right or up, and negatives move left or down.
A vector based Pac-Man game developed in Python.
Working in Python
Likewise, Python is an incredibly accessible programming language. In LXF262 we used Python to create a Lunar Lander Module game, and in LXF263 we created a side-scrolling game in Python. The original Pac-Man game was released between the two, Lunar Lander being 1979 and the first side-scroller being 1981. Python is perfect for our retro gaming projects. So let’s begin…
We will, of course, need Python installed. We’ll use Python 3 for this tutorial. If you’re on a Debian-based distro you can get set up with sudo apt-get update, followed by sudo apt-get install python3. We’ll also be taking advantage of a vector graphics module linuxformat.py which can be found at the source code link on our Archives page at www.linuxformat.com/archives. Once downloaded or copied, ensure linuxformat.py is saved in the same directory as the Python project we’re about to develop.
Start a new Python file. Using your favourite text editor create an empty file and save it in the same folder as linuxformat.py, which we’ll be using as a reference module for vector graphics. When it comes to programming, there’s no point reinventing the wheel every time. Start your new document off with a new modular imports:
from random import choice
from turtle import *
from linuxformat import vector
Next, we’ll want to declare and initialise all of our global variables:
state = {‘score’: 0}
path = Turtle(visible=False)
writer = Turtle(visible=False)
aim = vector(5, 0)
pacman = vector(-40, -80)
ghosts = [[vector(-180, 160), vector(5, 0)], [vector(-180, -160), vector(0, 5)],[vector(100, 160), vector(0, -5)],[vector(100, -160), vector(-5, 0)],]