A first-person 3D maze game built with Python and OpenGL. Navigate through a hand-crafted 30×30 maze, find the exit, and beat your time.
- First-person 3D rendering — perspective projection with textured marble walls
- Smooth movement — wall-sliding collision so you don't get stuck on corners
- In-game HUD — live timer displayed in the top-left corner
- Minimap — top-right corner overview with your position (red) and the exit (green)
- Win screen — centered overlay shows your final time when you reach the exit
- Dual control scheme — WASD and arrow keys both work out of the box
- Python 3.10+
- PyOpenGL 3.1.7+
- Pillow 10.0+
git clone https://github.com/Turan-Nadir/maze-game.git
cd maze-gameWith pip (recommended):
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtWith conda:
conda create -n maze python=3.11
conda activate maze
pip install -r requirements.txtpython maze.py| Action | Keys |
|---|---|
| Move forward | W or ↑ |
| Move back | S or ↓ |
| Turn left | A or ← |
| Turn right | D or → |
| Strafe left | , |
| Strafe right | . |
| Quit | ESC |
maze/
├── maze.py # Entry point — game loop, rendering, input handling
├── requirements.txt
├── texture/
│ └── marble.jpg # Wall texture
├── map.jpeg # Reference image of the full maze layout
└── src/
├── collision.py # AABB collision detection with wall-slide
├── cube.py # Textured unit-cube renderer (6 faces)
├── input.py # Keyboard state tracker (WASD + arrow keys)
├── movement.py # Camera movement vector calculation
└── texture.py # OpenGL texture loader via Pillow
The maze is represented as a 2D integer grid — 1 is a wall, 0 is open space. Each frame, the scene is rendered by iterating the grid and drawing a textured cube at every wall cell via OpenGL immediate mode.
Camera movement uses a simple step-distance vector offset based on the current rotation angle. Before applying a move, the new position is tested against the collision grid; if blocked, the code tries to slide along the unblocked axis so movement feels smooth near walls.
The minimap and HUD are drawn as 2D overlays by temporarily switching to an orthographic projection, rendering the UI elements, then restoring the perspective projection for the next frame.
MIT