A mind-bending 4D maze game built with Babylon.js that challenges players to navigate through multiple dimensional layers to find the exit beacon.
Experience navigation in four spatial dimensions - not just X, Y, Z, but also the mysterious W dimension. Each W-layer contains a complete 3D maze, and you must shift between these dimensional planes to reach your goal.
- ๐ True 4D Navigation - Move through W-layers using Q/E keys to access different dimensional slices
- ๐ป Ethereal Dimensional Hints - Subtle ghost walls and particles show where walls exist in other dimensions
- ๐ฏ Smart Goal Placement - AI ensures every maze is solvable with reachable exit beacons
- ๐จ Dynamic Visual Effects - Gentle dimensional distortions and atmospheric particles
- ๐ Spatial Audio - 3D positioned ambient sounds that respond to your movement
- ๐ Performance Monitoring - Real-time FPS and optimization metrics
- โก Optimized Rendering - Pre-generated geometry with intelligent layer switching
- Node.js 16+
- Modern web browser with WebGL support
# Clone the repository
git clone https://github.com/yourusername/4d-maze-game.git
cd 4d-maze-game
# Install dependencies
npm install
# Start development server
npm run dev
# Build for production
npm run build- Move: WASD or Arrow Keys
- Look: Mouse (click to lock cursor)
- Jump: Space
- Sprint: Shift
- Change W-Layer: Q (previous) / E (next)
- Help: H key to toggle help panel
- New Maze: R key to generate fresh challenge
- Exit Game: Esc to pause and unlock cursor
- Current Layer: The solid maze you can walk through
- Ghost Walls: Translucent walls showing barriers in other W-layers
- Portal Particles: Swirling effects indicate W-dimension passage points
- Exit Beacon: Golden glowing cylinder marking your destination
- Compass: HUD arrow points toward the exit with distance
- Use the compass to navigate toward the exit beacon
- If the exit isn't on your current W-layer, shift dimensions with Q/E
- Ghost walls help you understand the maze structure across all dimensions
- Portal particles show where you can move between W-layers
src/
โโโ config.js # Game configuration and constants
โโโ main.js # Application entry point
โโโ game-refactored.js # Main game orchestration
โโโ maze4d.js # 4D maze generation algorithm
โโโ Camera.js # Player movement and controls
โโโ MazeRenderer.js # 3D geometry generation
โโโ InputHandler.js # Keyboard/mouse event management
โโโ UI.js # HUD and overlay systems
โโโ DimensionalEffects.js # Visual effects and particles
โโโ DimensionalAudio.js # Spatial audio system
โโโ PerformanceMonitor.js # FPS and performance tracking
- ๐ฎ Babylon.js - 3D rendering and physics
- โก Vite - Fast development and building
- ๐จ WebGL Shaders - Custom post-processing effects
- ๐ Web Audio API - Procedural spatial audio
- ๐ 4D Mathematics - Higher-dimensional maze algorithms
Edit src/config.js to customize:
export const GAME_CONFIG = {
// Maze dimensions
CELL_SIZE: 3,
WALL_HEIGHT: 2.6,
// Default maze size
MAZE: {
DEFAULT_W: 3, // W-layers (4th dimension)
DEFAULT_X: 8, // Width
DEFAULT_Z: 8 // Depth
},
// Camera settings
CAMERA: {
SPEED: 0.28,
SPRINT_SPEED: 0.55,
FOV: 1.2
}
};- Ghost Walls: Semi-transparent representations of walls in other W-layers
- Particle Systems: Ethereal effects that hint at dimensional boundaries
- Portal Indicators: Visual cues showing W-dimension transition points
- Post-Processing: Subtle screen-space effects during dimensional shifts
- Pre-generation: All W-layers built at startup for instant switching
- Material Pooling: Reused materials across maze generations
- Selective Shadows: Only active geometry casts shadows
- Culling: Invisible layers are completely disabled
- Low-frequency drones create otherworldly atmosphere
- 3D positioned sounds at portal locations
- Dimensional shift audio during layer transitions
- Adaptive intensity based on player proximity to rifts
Uses recursive backtracking in 4D space:
- Initialize 4D grid with all walls present
- Start from random cell in 4D space
- Carve paths by removing walls between visited cells
- Ensure connectivity across all four dimensions
- Smart goal placement finds farthest reachable cell from start
- Real-time FPS monitoring with performance grading (A-F)
- Active mesh counting for optimization insights
- Memory usage tracking (where supported)
- Performance stability metrics with variance analysis
| Action | Keys | Description |
|---|---|---|
| Move Forward | W, โ | Walk forward |
| Move Backward | S, โ | Walk backward |
| Strafe Left | A, โ | Move left |
| Strafe Right | D, โ | Move right |
| Look Around | Mouse | Camera rotation |
| Jump | Space | Hop over small obstacles |
| Sprint | Shift | Move faster |
| W-Layer Back | Q | Previous dimensional layer |
| W-Layer Forward | E | Next dimensional layer |
| Toggle Help | H | Show/hide help panel |
| New Maze | R | Generate fresh challenge |
| Pause | Esc | Unlock cursor |
- ES6+ modules with clean imports/exports
- Functional programming patterns where appropriate
- Event-driven architecture for loose coupling
- Configuration-first design for easy customization
- Pre-generate geometry for instant W-layer switching
- Use object pooling for frequently created/destroyed objects
- Implement selective shadow casting to reduce GPU load
- Monitor performance metrics in real-time
- Visual Effects: Extend
DimensionalEffects.js - Audio: Enhance
DimensionalAudio.js - Maze Algorithms: Modify
maze4d.js - UI Elements: Update
UI.js - Configuration: Adjust
config.js
- Minimum: WebGL 1.0, 2GB RAM, 60 FPS target
- Recommended: WebGL 2.0, 4GB RAM, 120 FPS capable
- Browser Support: Chrome 70+, Firefox 65+, Safari 12+, Edge 79+
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Test thoroughly across different browsers
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Maintain modular architecture
- Add comprehensive comments for complex 4D math
- Test performance impact of new features
- Follow existing code style and patterns
This project is licensed under the MIT License - see the LICENSE file for details.
- Babylon.js Team - Incredible 3D engine
- 4D Mathematics Community - Inspiration for higher-dimensional navigation
- Web Audio API - Enabling procedural spatial audio
- Modern Web Standards - Making browser-based 3D gaming possible
- Live Demo: Play 4D Maze
- Documentation: Technical Docs
- Bug Reports: Issue Tracker
- Discussions: Community Forum
Experience navigation beyond the third dimension. Can you master the 4D maze? ๐