^^Finished product first^^
I’m building a point-and-click adventure game called Rio Borealis - a sci-fi western detective mystery set on Mars. And because I apparently have a deep need to make everything slightly more complicated than necessary, I wrote a Python script that turns my room layouts into ANSI-colored terminal art.
Here’s what a room layout looks like in the code:
grid = [
['wall','wall','wall','wall','wall','wall','wall','wall'],
['wall','carpet','carpet','carpet','carpet','carpet','carpet','wall'],
['wall','carpet','bed','bed','bed','carpet','carpet','wall'],
['wall','carpet','bed','bed','bed','carpet','carpet','wall'],
['wall','carpet','carpet','carpet','carpet','carpet','carpet','wall'],
['wall','carpet','carpet','carpet','table','table','carpet','wall'],
['wall','carpet','carpet','carpet','carpet','carpet','door','door'],
['wall','wall','wall','wall','wall','wall','wall','wall'],
]
The magic is in a 50-line function called get_direction(). For each tile, it checks all 8 neighbors and asks: are you the same terrain as me?
If all 8 neighbors match, you’re a middle tile: ▓
If three sides match but not the top, you’re a north edge: ↑
If you’re surrounded by the same terrain but a diagonal neighbor is different, you’re an inner corner: ◤
And if you’re near two or more different terrain types, you’re a transition point: ◆
ARROWS = {
'N': '↑', 'S': '↓', 'E': '→', 'W': '←',
'NW': '↖', 'NE': '↗', 'SW': '↙', 'SE': '↘',
'nw': '◤', 'ne': '◥', 'sw': '◣', 'se': '◢',
'M': '▓', '$': '◆'
}
Each terrain type gets its own hex color converted to ANSI escape codes. Wood floors are brown. Red carpet is… red. Hazard zones are orange. When you cat the .ans file in your terminal, you get a little color-coded map showing exactly where every tile edge should go.
I’ve now got 23 locations visualized this way - from Lucy’s Saloon to the mine crater floor. It’s not how most people design game levels, but it means I can see exactly what my tile transitions need to look like before I generate a single pixel of art.
Sometimes the best tools are the ones from 1985.