2
\$\begingroup\$

Tile-based games like Chess have a simple modal: an array of arrays, each coordinate with an X and a Y value. This is easy to implement, and it is easy to figure out what is going on.

Chess Board http://www.chesscentral.com/EasyEditor/assets/chess_board_blank.gif

However, when I see games like Civilization 5, I am not sure how hexagonal worlds are implemented. I have a couple ideas, but cannot confirm them.

  1. Each row of hexagons is represented in the modal by an array of tiles. This would be much like the first chess board, but would require more effort to figure out adjacent tiles.
  2. Each tile only know what tiles border it. When the game renders one tile, that tile loads the 6 around it, which repeats until the screen is filled with tiles.

Are either of these guesses correct? If not, how do developers implement these hexagonal maps?

Hexagonal Game Board

\$\endgroup\$
2
  • 2
    \$\begingroup\$ I'm betting this will answer most of your questions: redblobgames.com/grids/hexagons. And, since you're already comparing to square grids, this is a possible duplicate: gamedev.stackexchange.com/questions/76108/… \$\endgroup\$
    – House
    Sep 14, 2014 at 14:47
  • \$\begingroup\$ @Byte56 That post does a very good job of explaining it, so thanks for the link. On the other note, I don't think that question is a duplicate because it asks about the issues of implementing hexagonal grids, and I just wanted to know the theory behind it. It also talks about tradeoffs of hexagons over squares from an end-user perspective. \$\endgroup\$ Sep 14, 2014 at 14:56

1 Answer 1

3
\$\begingroup\$

For me, I do not see much difference hex-maps and plain 2D arrays. If you look at following picture - it is nothing more then array with some render offset for rows:enter image description here

As you can see, it technically really is an array. Array with "overriden" getUpper and getLower - some playing with indexes. Though I dont really know how they did it in Civ5, it really appears just as special case of "classic" tiled map.

\$\endgroup\$
2
  • \$\begingroup\$ Each row would need alternating getUpper and getLower functions, correct? Because row 1 may use the last image you include, but row 2 would need to get the tile in the bottom-left instead of bottom-right I would think. \$\endgroup\$ Sep 14, 2014 at 15:04
  • \$\begingroup\$ There are two "types" of rows - one offset half tile and the other one without it. So yes, there should be two implementations depending on odd/even. \$\endgroup\$
    – wondra
    Sep 14, 2014 at 15:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .