Member-only story

Building a Better Dungeon Level

How I updated an algorithm to better match the graphics

Nevin Katz
Better Programming
9 min readOct 13, 2022

Image by the author.

For the past seven months, I’ve been building a dungeon game in JavaScript and HTML5 Canvas. The game resembles what is known as a Roguelike, as rather than build the levels myself, I use an algorithm — a sequence of instructions that I translate into code.

Different algorithms produce different types of dungeons. For instance, when I implemented an algorithm called random walk, it produces a dungeon like the one below.

A sample game level. The player is blue, the enemies are red, and the items are blue and yellow.

As the name suggests, a “digger” stumbles randomly from the center outward and digs through the solid rock to create tunnels. It then returns to the center and keeps going until a certain amount of space is created.

After implementing random walk, I wrote some logic that drops rooms at random places on the map and then connects them with narrow corridors. While I also wrote this in JavaScript for the same game, it was based on a different algorithm.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Nevin Katz
Nevin Katz

Written by Nevin Katz

Developer at EDC. I write about web development and biology. Subscribe at https://buttondown.email/nevkatz for article roundups.

No responses yet

What are your thoughts?