Devblog #4 - Map Generation in a SNES Game
Map Generation in a SNES Game
While creating my game for the SNES, I encountered a problem with dynamically generating maps. Due to the limited amount of RAM in the console, I couldn't simply allocate a large array to store the entire map. I had to find a more memory-efficient solution.
What is ROM?
ROM (Read-Only Memory) is a type of memory that stores game data on a SNES cartridge. Unlike RAM, the content of ROM doesn't change during the game. Thanks to this, I can store pre-prepared resources like graphics, sounds, and game levels in ROM and read them into RAM when needed. This is crucial because the SNES has very limited RAM (128 KB), while cartridges can have from 512 KB up to even 8 MB of ROM.
Map Structure
Each map consists of rooms with dimensions of 10x10. The rooms are pre-designed and stored in ROM. The key aspect of this approach is that all rooms have entrances and exits in the same positions. This allows me to connect them freely, creating dynamic maps.
Why did I choose rooms with dimensions of 10x10? With this division, I can create diverse layouts. Rooms can take various shapes — they can be classic large chambers, sets of smaller rooms, short corridors, or even small mazes. This modularity allows for generating more interesting, non-linear levels without consuming large amounts of memory.
The room layout scheme is currently quite simple. I just declare a two-dimensional array where I store room identifiers. However, to prevent the map from looking like a simple rectangle, I added a special type of room representing 'nothing' — a room with no entrances. This way, the map stops resembling a typical rectangle and gains a more organic shape.
Map Generation Process
- Defining the map layout — I first define the map size and the general room arrangement scheme.
- Random room selection — For each position in the map grid, I randomly select one of the pre-prepared rooms, ensuring its entrances and exits match adjacent rooms.
- Connecting rooms — I make sure that the rooms are correctly connected, enabling movement throughout the entire map.
- Saving and displaying the map — Once generation is complete, the map is ready to be used in the game.
Advantages of This Approach
If I tried to store the entire map in RAM, I would quickly run out of available memory. By saving predefined rooms in ROM and combining them randomly, I can create large, dynamic maps without occupying valuable RAM. This also makes it easy to add new rooms and increase level variety without increasing memory demand.
This approach has another advantage — I can create many interesting rooms myself, which will then be used randomly. Since each room takes up only 100 bytes, I can create a lot of them without worrying about technical limitations. If necessary, I could further reduce the room size. In its current form, a room consists of only two types of characters: ' ' (floor) and 'x' (wall). Nothing stops me from using 0s and 1s instead, which would allow storing a room as 8x8 bits, requiring only 8 bytes.
Thanks to this solution, I can create diverse maps without consuming a large amount of RAM, which is crucial for the SNES platform.
Get The Hexer's Path
The Hexer's Path
Status | Prototype |
Author | 8BitGlitch |
More posts
- Devblog #5 - Character Development1 day ago
- Devblog #320 days ago
- DevBlog #2 - 7DRL22 days ago
Leave a comment
Log in with itch.io to leave a comment.