This was originally for Day 1: Use a technology that you're intimidated by, but I didn't get to finish it on that day. It's based off of a couple of tutorials that I found really helpful:

  • This raycaster tutorial, and this explanation
  • This maze generation algorithm using a form of recursive backtracking

How it Works

A raycaster creates a psuedo-3D environment by taking a 2D grid where walls are a certain value (e.g. 1) and space is a certain value (e.g. 0). Then, based off of the player's location in that grid, rays are drawn from the player within the player's POV until the rays touch a wall or reach a certain length. Based on the lengths of these walls, vertical lines are drawn on the screen with varying lengths, creating a sort of 3D effect that's super basic (under 300 lines of code) but pretty cool. Rain is simulated with white lines in random places.

Rays

The maze algorithm works by using a stack. It starts at a random cell, chooses a wall to remove, and moves to that cell after adding itself to the stack. This happens over and over again until we reach a dead end, where all the surrounding cells have been visited, in which case we pop off the current cell to return to the previous cell and look at the other available surrounding cells. The recursion (which is implemented iteratively) stops once all the cells are visited.

Since we're carving passages, there's an extra algorithm to scale the maze to a map where the walls are carved.

Built With

Share this project:

Updates

Submission history