Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Representing a Hex Map

This topic is 5914 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m sure a lot of you have built games where you have a hexagonal map before, I was wondering what you found to be the best way to represent it when programming? As far as I can tell there are two options: 1) Use a "tile" object to represent each hex tile, it will have pointers to the tile adjacent to it (You could probably also get away without pointers by using an array). 2) Use a "square" grid to approximate the hex grid. I can see pros and cons to both ways. The application I have in mind is a turn based game, so it doesn''t have to be lightning quick - but I''d rather have as fast an implementation as possible within reason. I guess it should be fairly easy to deal with... So any suggestions? Past experiences? Thanks! - FlanMan

Share this post

Link to post
Share on other sites
It all depends on how much you want to spend on making this game better. Implementing a hexagon grid will take a lot more programming than a square-shaped grid, with a questionable amount of improvement to the gameplay. If you ARE going to use a hex grid, go whole hog and store the tiles as hexagons, rather than approximating hexagons with squares. Since your program is turn-based, there is almost nothing you could do that would ever noticably slow the game down, since you don''t have to process a screen-full of graphics every 40th of a second.
However, siaspete has a good suggestion also - you could just go with a grid of squares and then draw them skewed (as parallelograms) on the screen - this means a lot less coding for you, but it still looks sort of "3d-like". You would just store tile info in probably a 2d memory array, then access that array every time you draw to the screen.

Twilight Dragon
Win32 API Programmer

Share this post

Link to post
Share on other sites
TDragon: you''re missing the point.
He didn''t asked if he should make the game hex or square grid based, nor the way to draw it!
He is going to make a hex tile based game and asked how to represent this grid of tiles in the program. Nothing graphical.

I''ve never worked with hex-tile based stuff, but i think a square array will be easier to manage than representing each tile as an object with neighbours.
With the array, you can access everything more directly, easier and i find it personally easier to represent and to work with.
It''s maybe also because i don''t really understand how you would manage tiles as objects with pointers to it''s neighbours. Easy things like finding distances between tiles can become complex: how do you find out the distance, the right path? (the tiles doesn''t know the direction their are from each other, and there are nearly unlimited ways to reach 2 tiles)


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!