2

I've made a random 2D tile-based dungeon generator in Python (and PyGame), which is a basic 2D array of wall and floor tiles, and it works great, filled with rooms and corridors. But now I want to go around the rooms and corridors with nicer wall sprites (top-left corner, top-right corner, etc).

EDIT: To expand a bit without going into the whole process, an empty 2D array is created (as the level map) consisting of 0 values (empty). Rooms of random size are "placed" at random locations within the 2D array, and linked by corridors. Rooms and corridors are given a value of 1 (floor). It's easy to just outline the rooms and corridors with a single square wall sprite, but I want to have dynamic walls that have shape to them (corners, ends, that sort of thing).

I have tried a few different ways - generating the dungeon then checking edges and replacing wall parts, or creating the wall parts around each room as it's generated, but there's always problems where the corridors cross into rooms, and the order in which the wall parts are determined.

I've searched Google, Roguebasin, etc but I can't find anything about this. Every random generator I find just uses 2 simple sprites (floor and wall). I don't want my "walls" to look generic. I also wanted to steer clear of prefab rooms because I want it to be completely random.

I've been stuck on this for 2 weeks. I'm making my own engine in Python, and there are lots of examples of random dungeon generation, but I want to go a step further and make the dungeon look great with nice corners, horizontal and vertical walls, etc.

Do I incorporate the wall parts into the generation? Or do I go over the generated map afterwards with an algorithm for choosing the correct parts, or is there something else I've not thought of? Or am I punching too high, should I stick with a basic roguelike setup?

Here's a mock-up of how I want it to look (or similar). As you can see, I'm not a stranger to pixel art and sprites, but I want the computer to be able to randomly generate the rooms and corridors, AND populate the correct wall parts:

Dungeon Mock-Up

Jayce
  • 539
  • 6
  • 21
  • Can you break down the random generation a bit further? Instead of just wall and floor, wall, floor, and edge, like you said? An edge would have the outmost pixels a random solid color maybe? You could just have one edge also, and rotate it depending on which part of the wall, top, side, etc. I assume you're assembling the random blocks onto a room of certain dimensions so you have awareness of which block is bein assembled onto which part of the room. You can also achieve consistency by have the room track the random edge color or whatever. – user176692 Jun 13 '20 at 19:27
  • My generator consists of a 2D array of wall tiles and floor tiles (as I said). Basically 0s and 1s blitted to the screen as a wall sprite or floor sprite. I cannot explain the whole concept of dungeon generation here, but the question was about the methodology of replacing the generic wall tiles with more dynamic wall parts (such as top-left corner, top-right corner). – Jayce Jun 13 '20 at 19:45
  • Oh I see, so your walls do not have fixed layouts, sorry bit hard to visualize this without much Roguelike experience. Random map generation is an art, not just in 2D. The search term I'm familiar with is procedural (map) generation. A few ways you can solve problems here are by limiting the randomization to just walls that do not intersect with corridors or regenerating the walls until they meet certain criteria i.e. they are narrow enough to allow a corridor through. – user176692 Jun 13 '20 at 21:36
  • I've added a picture to better illustrate what I am after. Yes, they do not have fixed layouts - as I say, they are "random." I understand that procedural map generation is not just limited to 2D, but in my case it is 2D. Understanding the principles of tile-based map generation in Roguelikes is kinda requisite here in order to make suggestions on it, but thank you for your candor, I appreciate the effort. – Jayce Jun 13 '20 at 22:17
  • OK, yeah thought 'roguelike' was an adjective, see the tag now. If your Tile Rule falls through, see some other dungeon generator algorithms here https://www.gridsagegames.com/blog/2014/06/procedural-map-generation/. Good luck. – user176692 Jun 13 '20 at 23:57
  • Thank you, I appreciate your input. I'm considering starting from scratch with a completely new generator for my tile rule, so I'll bear these in mind. – Jayce Jun 14 '20 at 08:42

2 Answers2

2

I found a video on Unity's Tile Rule feature, and setting up rules for tiles so that the tile reacts to the tiles around it.

Here is a link to the video I watched that gave me the idea: Tilemap: Rule Tile

I have successfully now coded tile rules into my game, and it works really well - the map is randomly generated with rooms connected by corridors, and then works around the floor tiles, assigning the correct wall part based on my rules.

Hopefully this will serve as a signpost for any devs doing the same kind of work.

Here is a screenshot of a randomly-generated level with the walls now auto-generated:

EverDark - walls complete

And here are the rules I designed using Excel:

EverDark - tile rules

Ticks on a black background mean a wall is required in that space, a blue background means a floor is required in that space. I'm not sure if there is a quicker or better way of doing this, but it's worked for me.

Jayce
  • 539
  • 6
  • 21
0

I don't exactly understand you but I can say you need to define which "Tile" going to pair with which tile, like you don't want to pair ground tile with wall tile.

if you make that logic work with code you can make corner pieces pair with normal wall or door pieces pair with walls.

and there is a lot of videos you can make a map an AI trained by a grayscale image that has understood your wall, ground, door placement and generates maps like your style.

d3r1n
  • 45
  • 1
  • 6
  • I'm very intrigued by the part about AI that can understand the map - that is what I am looking for; to make the computer understand where to place certain wall tiles so that they join up correctly, based on the layout of the floor and the surrounding empty space. – Jayce Jun 13 '20 at 20:41
  • I've edited the question to better explain what I am looking for. – Jayce Jun 13 '20 at 22:18