Skip to content
← Back to the shelves

A University Project

Pac-Man

2024

Pac-Man, cover picture
Plate I

Ingredients

  • Python
  • PyOpenGL
  • GLFW

Subjects

  • Computer Graphics
  • OpenGL
  • Game AI

About

My project for the Computer Graphics course at Shiraz University (Spring 2024). The goal was a complete, playable game using only low-level OpenGL primitives, so everything on screen, including the menu text and the win/lose screens, is drawn from quads and triangle fans. Game logic is separated from rendering and uses delta-time movement, so it runs at the same speed on any monitor.

Features

  • Three difficulty levels that change how fast the ghosts move.
  • Ghost AI — four ghosts driven by a greedy chase algorithm that turns into a flee algorithm while Pac-Man is powered up.
  • Power pellets — for five seconds the ghosts turn blue and can be eaten, sending them back to the ghost house.
  • Teleport tunnel connecting the left and right edges of the maze.
  • Wall collision for Pac-Man and the ghosts, with a cornering assist so turns do not need pixel-perfect timing.
  • Win and lose screens, score in the window title, automatic restart.

How it works

The window is a 2D orthographic view of clip space drawn with immediate-mode OpenGL. Walls are quads, pellets and ghost bodies are triangle-fan circles, and Pac-Man is a fan with a wedge left out for the mouth that opens and closes on a timer. The maze is a 28×28 grid; movement is continuous but collision is resolved against the grid.