Overview
The maze is procedurally generated using a Tetris-like piece placement algorithm, creating unique layouts for every game. TheMyMaze class manages the entire tile grid and collision system.
Tile Types
Each tile in the 28x31 grid represents a specific game element:| Value | Type | Description |
|---|---|---|
0 | Wall | Solid blue walls with shader effects |
1 | Empty | Walkable space without collectibles |
2 | Dot | Small collectible dots (most common) |
3 | Pill | Large power pills (make ghosts vulnerable) |
4 | Teleport | Portal tiles on left/right edges |
MyMaze Class Structure
Properties
Maze Data Structure
The maze is stored as a 2D array (31 rows × 28 columns):Tile Construction
Each tile is created based on its type:Walls have hitboxes (
has_hitbox: true) while walkable tiles do not, optimizing collision detection.MyTile Class
Individual tiles are created with theMyTile class:
Collision Detection
The maze handles collision detection for all characters:checkCollision Method
The collision system checks 3 tiles in the direction of movement: the direct tile plus two adjacent tiles, ensuring smooth collision detection at corners.
Tile Type Checking
Navigation and Pathfinding
getNeighbors Method
Used for A* pathfinding and determining valid turns:Dot Collection
removeDot Method
Called when Pac-Man collects a dot or pill:Tracking Progress
dotNumber == 0 to determine when the level is complete.
Teleport System
Portals allow characters to wrap around the edges of the maze:Teleport tiles are always placed in pairs on opposite sides of the maze, allowing seamless wrapping.
Procedural Generation
The maze uses a multi-stage generation algorithm:1. Tetris Piece Generation
2. 3×3 Expansion
3. Full Maze Assembly
Shader Effects
Walls use custom shaders for visual variety:Each maze generates a unique color scheme and pattern variation, ensuring visual diversity across games.