Sunday, June 9, 2019

turn based strategy - How to draw the contour of a hexagon area, like in Civ 5


I am trying to achieve the hexagon contour look you find in Civilization V:


http://blogs.forbes.com/davidewalt/files/2010/09/civ5_screenshot.jpg



I want to outline the area a unit can move to on a hexagon grid, so far I can get a list of all the tiles a unit can move to and from that select the tiles that are on the boundary, which looks like this:


Boundary Tiles


Assume the list of boundary tiles are in random order. I can also get a list of all the corners on each hex. As you can see above the island in the middle would create a hole in the contour shape, Civ 5 also seems to handle these holes nicely:


enter image description here



Answer



The logic is simple: your contour is the set of all the edges that separate border tiles from non-border tiles. You can code the following:


for each boundary tile
for each edge
if edge is shared with a hex tile that is NOT in the boundary tile list
mark as contour edge

render all contour edges

Note that if you want the contour to encompass the whole green area, rather than just the boundary tiles, then the condition becomes "if edge is shared with a hex tile that is NOT in the green tile list", and the outer for loop becomes "for each tile in the green list"


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...