Skip to content

omkrishna/Maze-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 

Repository files navigation

IITD x Pacman

A two player pacman-ish maze game built as part of the course COP290 under Prof. Rijurekha Sen
Authors : Harshita & Om

ezgif com-gif-maker (4)

Getting Started

Dependencies

  • G++, which is a C++ compiler
  • SDL 2.0 (We go through installing SDL on a ubuntu system, and give links for other OSs

Installing

Assuming you have g++ installed, here's how to install the sdl libraries on a ubuntu system :
#install sdl2
sudo apt install libsdl2-dev libsdl2-2.0-0 -y;

#install sdl image  
sudo apt install libjpeg-dev libwebp-dev libtiff5-dev libsdl2-image-dev libsdl2-image-2.0-0 -y;

#install sdl mixer  
sudo apt install libmikmod-dev libfishsound1-dev libsmpeg-dev liboggz2-dev libflac-dev libfluidsynth-dev libsdl2-mixer-dev libsdl2-mixer-2.0-0 -y;

#install sdl fonts
sudo apt install libfreetype6-dev libsdl2-ttf-dev libsdl2-ttf-2.0-0 -y;

Link for other OSs

Running the game

git clone https://github.com/omkrishna/COP290-TASK2.git
cd PacMan
make

Game Logic

Character Logic

The Game has two main characters - students PacMan and PacWoman. They move around the maze taking inputs from the keyboard - Arrow Keys in single player mode and Arrow Keys and WSAD KeySet in two-player mode. In single player mode, the game randomly chooses the student as PacMan or PacWoman, who initially stands at the top left empty tile. In two-player mode, PacMan and PacWoman randomly occupy one of the top-right and top-left empty tiles. The Students score by picking up Pellets, PoRs and Audits. A Student wins if they collect all the pellets before failing. The users cannot pause the game because Students at IITD never get a break.

Ghost Logic

The Game has 3 Ghosts - courses COP, ELL and HUL. They move around the maze following agorithms computed in real-time. The Ghosts cannot step on Tiles and never take an about turn. The courses calculate the distance to their target tiles from the available places they can move to, and shift over to the place with the minimum distance. Whenever a Course collides with a Student, the Student is deemed failed and stops taking keyboard inputs. The speed of the Courses - the WorkLoad - is decided at the welcome screen, where the user choses their level - beginner, intermediate or advanced.

In single player mode, COP's target tile is the Student itself. HUL's target tile is 2 tiles ahead of the Student. And ELL's target tile takes into account the positions of the Student, COP and HUL, owing to its unpredictable and erratic behavior. It lies in the same line as COP and HUL's target tiles such that HUL's target tile is in the exact middle. However, in multiplayer mode, COP and HUL each chase one Student and ELL roams with respect to the positions of COP, HUL and the two Students. If one Student fails, all Courses turn to Relative Grading and chase the remaining Student.

In case a Student picks up a PoR Pellet, the Courses enter into a Backlog Mode for a few seconds, i.e. all their target tiles are set to their respective corners in the screen - top-right, bottom-right and bottom-left for COP, HUL and ELL respectively. In the event that a Student picks up an Audit Pellet, the Courses enter into 30% Effort mode. Their target tile is the usual, but when they get in the radius of 8 tiles around the Student(s), they idle out and target tile shifts to their respective corners. When all Students in the game have failed, the exit animation pops up where the Courses do a little victory dance (by moving randomly irrespective of the other sprites) before the exit screen.

Maze Logic

The maze generation logic was done after consulting various available resources for creating random mazes. The usual DFS approach did not produce pacman-like mazes and was immediately discarded. We looked at Shaun Lebron's code (link in acknowledgement) for the initial idea. Though we could follow his logic completely, we did understand that we needed to stack together Tetris-like blocks keeping in mind a few constraints. We decided on a screen size of 27x21 tiles, where each individual tile was 40x40 pixels. The constraints that we decided upon were :
  • paths are one tile thick, whereas blocks are atleast two tile thick
  • outer boundary is always blocked with a few potential tunnels
  • IITD written across the center
  • blocks can be rectangles, T-shaped, inverted T shaped, or any variant of L shape
The problem reduced to stacking these blocks using a dozen or so randomly generated numbers. For more details, feel free to checkout Pacman/Map/mazegen.cpp. The kinds of mazes that this algorithm was generating were :

Follow Up

Acknowledgments

  • Lazy Foo's sdl tutorials are a must watch for anyone who wants to try out SDL. Music, Textures, Fonts, TileMaps - this tutorial has everything covered as far as SDL is concerned.
  • Shaun Lebron's article on Random Pacman maze generation was a very tough read but gives excellent results. We couldn't follow his code but did get the idea of stacking tetris-like blocks together to generate mazes.
  • This Youtube video gives a great insight about the algorithms ghosts follow to set their targets in pacman. Fascinating stuff
  • Prof. Rijurekha Sen, for being so helpful and considerate throughout the semester

About

IITD x Pacman

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published