Legacy GM Coordinates For Hexagon Tiles

Morkinas

Member
What is the best way to make a code that would read numbers 13, 14, 22, 24, 33, 34 as "neighbors = true" for number 23? (numbers are coordinates for hexagon tiles) And it would work with any number.

11 12 13 14 15...
...21 22 23 24 25...
31 32 33 34 35...


1,1 1,2 1,3 1,4 1,5...
...2,1 2,2 2,3 2,4 2,5...
3,1 3,2 3,3 3,4 3,5...
 

NightFrost

Member
If you write your code around the concept of having six coordinate directions, you can represent them with single values of -10, -9, +1, +11, +10 and -1 (instead of a x/y direction). Plus some checks for map edge cases.
 
W

whale_cancer

Guest
If you write your code around the concept of having six coordinate directions, you can represent them with single values of -10, -9, +1, +11, +10 and -1 (instead of a x/y direction). Plus some checks for map edge cases.
I believe even and odd rows would require slightly different values, but NightFrost has the correct idea.
 
W

wantafanta

Guest
Continuing with what NickFrost suggested.

If the data_stucture stores the hexagon values is stored as a 2D array or Grid.
And if the size of the grid changes room to room, you can calculate the difference between top and bottom rows by adding or subtracting the width of the array.

You would do something like this:
Code:
s = index // where ever your inital starting position is
n = array_length_2d(hex_grid,0)

    s-n
-1 , s , +1
    s+n
You would also add s-n-1, s-n+1, s+n-1, s+n-1 but for the sake of clarity in the diagram I excluded them.
 

TheouAegis

Member
If you Google it, I remember reading many many years ago a Blog about how to calculate various aspects of hexagon grid games.
 
Top