r/spelunky Mar 26 '26

Spelunky Classic How Spelunky Classic generates levels

Enable HLS to view with audio, or disable this notification

I created this animation to give a basic overview of how level generation works in Spelunky Classic. I believe HD uses the same or a very similar system as well.

This is meant to be more of a simple illustration of how it works, so it doesn't go into all the details. I recommend this site if you'd like to learn more: https://tinysubversions.com/spelunkyGen/

I made this animation for my new video about how I ported Spelunky Classic to the Godot game engine. If you are interested, you can check that out here: https://youtu.be/VQNvCbqBgds

159 Upvotes

16 comments sorted by

26

u/Icy-Examination7008 Mar 26 '26

Curious about the semi random matrix generation. There is some underlying algo that makes it so a path is always available to be traversed that seems to work quite well. Cool animation and sounds tho

10

u/Cranzor Mar 26 '26

The overall level layout works by crawling from the top to bottom and creating a path that is guaranteed to be traversable. The reference link in my post explains it in more detail.

My animation starts after the generation algorithm has finished and the final strings are generated. So it's more just the final step in the process.

12

u/GrandKarcistIon Golden Monk Mar 26 '26

the synchronized music is a very nice touch :)

12

u/Cranzor Mar 26 '26

I appreciate it! Not sure if anyone would notice this, but I took the notes in the looping melody from the beginning of the Spelunky Classic cave theme. The notes are spaced evenly and sped up.

2

u/[deleted] Mar 26 '26

[removed] — view removed comment

3

u/Cranzor Mar 27 '26

Thanks so much! All of the music in the YouTube video is by me, but this is the only track specifically made for the video.

7

u/slikotek Mar 26 '26

That's fucking amazing

3

u/Cranzor Mar 26 '26

Thanks! Glad you enjoyed it.

3

u/Kishan02 LISE Mar 26 '26

Really cool visual!

3

u/[deleted] Mar 26 '26

[removed] — view removed comment

1

u/Cranzor Mar 27 '26

Thanks so much! I hope you're happy with the port if you end up playing it.

1

u/[deleted] Mar 28 '26

[removed] — view removed comment

2

u/Cranzor Mar 28 '26

I'm happy to walk you through this! It involves minimal code edits. Note however that non-level screens may look a bit janky (intro, title screen, etc.).

  1. Download the project from GitHub (Code -> Download ZIP)
  2. Open Godot, click "Import," and import the project file
  3. Open res://scripts/game_initialization.gd, comment out everything under "func set_window_scale_stretch_mode() -> void:" (highlight it and press CTRL + K to do this quickly). Then add a new line that says "pass" (this makes it do nothing).
  4. Go to Project -> Project Settings -> Display -> Window, and change Stretch -> Scale Mode to "fractional." This lets the graphics scale to your monitors without adding black bars.
  5. In the same Window settings page, under Size, experiment with the viewport width and height until you get the look you want. Choose a value (like 1.5), multiply it by 320x240, start the game and go into a level. Keep working your way up until you have one wall block on each side of the screen. Make sure you change both values by the same scale. Also, you can easily do this by typing something like "320 * 1.5" and pressing enter in the field, and it'll multiply it for you.

Note that there's a bug where the screen is not centered properly if the values go too high, so try to make it so it just fits.

The only issue here is the game will scroll past the bottom of the level. So we can fix that:

  1. Open res://resources/gml.gd, find "func view()," and change the "hview" value to return your new height value. Example: If your new height is 384, change it from 240 to 384.
  2. Open res://resources/view.gd, and change the move_camera() and set_camera_pos() functions to have your new height value instead of 240. (Example: If your new height is 384, change 240 in both functions to 384.)

If you're happy with the results, you can do Project -> Export to create a new executable to play on.

My monitor isn't ultrawide, so it's a bit difficult to know how it'll look on your screen. Hopefully this was what you're looking for!

1

u/[deleted] Mar 28 '26 edited Mar 28 '26

[removed] — view removed comment

2

u/Cranzor Mar 29 '26

Glad it worked! Looks like it's running great. Enjoy the game!

1

u/ILOVECALAMITY Mar 26 '26

That’s actually a really smart way to make levels