Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best data structure to store a hexagonal tilemap

I am programming a 2d game, and I was wondering what the best data structure would be to store all of the hexagonal tiles in a map class? This is in java.

like image 698
Cayle Avatar asked Nov 30 '25 20:11

Cayle


1 Answers

Just use a 2D array, but have the "rows" and "columns" at a 60 or 120 degree angle to each other.

My quick ASCII illustration:

0   1   2   3   4   5   6  
  1   2   3   4   5   6  
1   2   3   4   5   6   7
  2   3   4   5   6   7
2   3   4   5   6   7   8
  3   4   5   6   7   8
3   4   5   6   7   8   9

(the numbers are row numbers, the column numbers are obvious...)

Effectively, you want to "stripe" the rows across the columns.

like image 54
mikera Avatar answered Dec 03 '25 10:12

mikera



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!