Drawing a path on a grid

Recommended Posts

I'm making a game where people can design their own castles, and I'm not sure how to go about making the walls connect up properly. I have different tiles such as crosses, t-junctions, corners, straight lines, diagonals, straight to diagonal, etc, and I need to know which one to use based on each tile's adjacent tiles. I was thinking some sort of lookup table but I don't have any experience using them and wouldn't know where to start. Another option would be to have 8 different wall sections compromising the 8 directions, that meet in the middle, and use them according to which tiles are adjacent. However, they wouldn't meet perfectly in the center so I want to avoid this option if I can.

Share this post

Link to post

Share on other sites

Each tile has 8 other tiles touching it, so you can use a char/8-bit int to represent the surroundings.

You need to create an array of 256 different wall pieces, one for each setup of the surrounding walls. (you can create a smaller amount of them and get the rest by rotating/mirroring)

That assumes you want diagonal lines of wall too, but that might not be what the user wants so you could allow diagonals only if there is no "straight" walls connected next to the diagonal wall. (example: bottom block and the block right to it are wall and the center of course. The user might want L instead of |\ in that situation)

0

Share this post

Link to post

Share on other sites

Oh and if you dont want to allow certain setups like in the example, you can leave the array empty in those spots IF you handle the not-allowed setups separately (set bits off in the 8-bit index if theyre in a bad setup to mark you dont want a diagonal there)

It might be simpler to just have the desired output in the array in those spots (so a single setup appears multiple times in the array)