I realize that many questions about pixels and hexagons have been asked, but I'm struggling to understand a certain aspect of it. Also, I'm not sure how much of a difference it'll make, but I am working in Java.
Starting off with my comprehension of the matter, I understand a Cartesian grid could be stored in a 2d array so that coordinates on the board are each an entry in the 2d array. But, I want to use a hexagonal sort of grid for a better game grid, like described on Amit's page http://www.redblobgames.com/grids/hexagons/.
I understand the concept after the hexagonal grid has been created (using x, y, z to get neighbors), but am struggling to store my coordinates. Previously, each coordinate had corresponded to an entry in the 2d array (cartesian). Now, I'm not sure how to make it correspond to get a hexagonal relationship between the coordinates.
Following the guide, I tried to offset the coordinates every other row (specifically trying the even row offset example from the link), like so:
In this, the top is the coordinates and the bottom is the visual representation of the array (blank spaces are entries with sentinels to 'skip' over, and 1s are the entries that correspond to the coordinates).
So, the neighbors of each coordinate are { {-1, 1}, {1, 1}, {1, -1}, {-1, -1}, {0, 2}, {0, -2} }. However, I don't think this is properly done? I thought of other ways to implement a hexagonal grid, which were to use a doubly linked list sort of structure and start off from the middle and relate the coordinates as 'nodes', or to hard code a map (which is sort of impossible because I plan for a large map). But, I'd rather stick with the offset idea because it's easier to use.
I think my problem is that each other row should be shifted by 1/2, but I give it 'holes' (sentinel entries). Maybe I'm supposed to convert coordinates to a hexagon using the geometry of hexagons. but I don't understand how I can use those individual hexagons when I want to path find unless they were stored in some data structure. Any code or help would be greatly appreciated.
