3D Maze

Publicado 2023-06-12


Generates a random maze, then places the player in the middle of it and ensures that you're not staring straight at a blank wall. Find your way to one of the corners and it will reset with a new maze and plonk you back in the middle. Not really intended as a game, just a learning exercise for me and the hope that the code will be of use to someone with more creativity than myself:)

Arrow keys to move forward/backward and turn.
Z/X will sidestep left and right
Hitting 'P' at any time will generate a new Maze and place the player in the middle of it.

This is an extension of my previous raycaster. I had to adapt the raycaster logic a bit to handle the maze walls rather than a grid based map.
This runs consistently at 60fps on my pc with 2:1 horizontal scale (i.e. 240 rays). You can change the 'scale' global variable to 3 if you have a slower machine.
The maze generation logic is a 'recursive backtracker'. Based on Dan Shiffman's excellent JavaScript tutorial on youtube here.