|
Hello gang,
Has anybody been wondering how
to get around in a map made up of hexagons instead of squares. The
best games I've played with this type of map system is Fallout 1&2 no doubt
about it. It took me several days to figure out and a couple more to mesh
it out. All that time spent in my quiet corner at the 2nd floor of the
local Mc Donald's with Large Fries and Large Rooter in hand can really help the
creative juices flow. It turns out after many trials and errors that the
best solution is the simplest one. First of all we have to keep in mind
the major difference between a hex grid and a square grid is that squares give
you 4 to 8 directions to move in while hexes have only 6 ways to go. So
how do you move from tile to tile? Well, although this grid I will use as
and example is set on a point (meaning flat sides on the left and right and
angles on top and bottom) it can easily be adjusted if you want to your
hexes set on a base or to have flat tops and bottoms and the
angles on the sides. (just turn the whole thing arrays and all 90 degrees)
Now imagine your grid as a simple x/y coordinate system with each array
representing a hex tile. I actually solved this using dice and moving them
around. If you wrote this on graph paper and moved every odd row 1/2
square to the right you would begin to see how you can move around since
all the tiles around every single tile would be arranged and accessible in
a hex pattern. To clear up which tile is which lets number the top tile 0
and number the rest beginning with the upper right tile 1 to 6 in a clockwise
manner.
Before
| |
| |
--------------------------------------------------
|
6 | 1
|
---------------------------------------------------
| 5 | 0
| 2
|
---------------------------------------------------
| 4 | 3
|
---------------------------------------------------
| |
|
|
After
| |
| |
--------------------------------------------------
|
6 | 1
|
---------------------------------------------------
| 5 | 0
| 2
|
---------------------------------------------------
| 4 | 3
|
---------------------------------------------------
| |
|
|
Assuming x is rows and y is columns going left and right is a simple x-- or x++
respectively;
but lets say you want to go to tile 6, easy looking
at the grid below that tile is located x--,y-- and the others pretty much show
where they are too.
EVEN
1
2
3
4
5
1
| 6 | 1
|
|
---------------------------------------------------
2
| 5
| 0
| 2
|
*zero's y is 2 w/c is even so variation = 0
---------------------------------------------------
3
| 4 |
3 |
|
---------------------------------------------------
4
| |
|
|
But it doesn't end there, going up and down changes
the arrangement of the tiles. This is solvable since there are only 2
variations w/c I've tagged ODD & EVEN.
To know which variation to use you have to get the
last bit of your y value.
i.e.. variation = y & 0xfe; (11111110)
This will block out all but the last bit telling
you if y is an odd or even row.
ODD
1
2
3 4
5
1
| |
| |
---------------------------------------------------
2
| |
6 | 1
|
---------------------------------------------------
3
| 5 | 0
| 2
| *zero's y is 3
w/c is odd so variation = 1
---------------------------------------------------
4
| |
4 | 3
|
---------------------------------------------------
5
| |
|
|
Therefore;
to get to tile 1
targetX=x+variation;
targetY=y-1;
to get to tile 2
targetX=x+1;
targetY=y;
to get to tile 3
targetX=x+variation;
targetY=y+1;
to get to tile 4
targetX=(x-1)+variation;
targetY=y+1;
to get to tile 5
targetX=x-1;
targetY=y;
to get to tile 6
targetX=(x-1)+variation;
targetY=y-1;
The only downside I have found is that you waste about
half of 1 column of arrays since you don't get to use them at all. No big
loss, really.
Now the next thing I'm planning to improve on this
is pathfinding and line of sight. Anybody got suggestions?
Well, that's it. I hope this has helped someone
out there. It was about time I contributed something to the list.
Sincerely Yours,
Luis
|