Drawing a path on a grid

Started by
4 comments, last by Calneon 11 years, 10 months ago
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.
Advertisement
Try looking into A* Pathfinding,
Here's tutorial on it:
http://wiki.gamegardens.com/Path_Finding_Tutorial

I'm sure there are also easier to understand tutorials on youtube :P
My problem has nothing to do with pathfinding.
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)

o3o

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)

o3o

Thanks! In the process of making my lookup table at the moment, time consuming stuff ha. Made an array that stores the adjacent cells and I get the lookup value like this:


[source]LookupValue = int(Connections[0]) << 7 |
int(Connections[1]) << 6 |
int(Connections[2]) << 5 |
int(Connections[3]) << 4 |
int(Connections[4]) << 3 |
int(Connections[5]) << 2 |
int(Connections[6]) << 1 |
int(Connections[7]);[/source]

BTW that's UnrealScript if anything looks funny.

This topic is closed to new replies.

Advertisement