문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

Just simple 2D array is good idea, you have all the info you need there :

enter image description here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top