Advertisement Jump to content
Sign in to follow this  

How to make Hexagonal maps? (C#,GDI+/DirtectX)

This topic is 4897 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

Hi community, does anyone have some code which shows how to draw a hexagonal map and keep track of all hexagons? I can draw a single hexagon at the moment, but i have no clue how to make a complete map and even more i need to know how i can index the hexagons, so that i can access them later (so for example: hex[1,3].XXX) with clicking on it with a mouse. I am using C# and GDI+ or Directx (the API depends on where i can find more understandable examples for). Since i am a noob, please try to explain as easy as possible. Thanks for your time!

Share this post

Link to post
Share on other sites
How are you organising them? If like this:
    __    __
__/a \__/b \.
/c \__/d \__/
\__/e \__/f \.
/g \__/ \__/
\__/ \__/ \.
/ \__/ \__/
\__/ \__/
you can reference them as a normal 2D grid, so:

a: (0,0)
b: (1,0)
c: (0,1)
d: (1,1)
e: (0,2)
f: (1,2)
g: (0,3)

(It's easier if you imagine them rotated 90°, but ASCII art gets mucky then). It's just a case of remembering that every other row is shifting along half a unit when displayed. In terms of detecting a click, a bounding-box test for four corners would be alright for an easy method.

Share this post

Link to post
Share on other sites
In my game X-hex X-HEX I referenced them from tope left being 1 .. bottom right being the last hex .. So I referenced then like so:

__ __
__/4 \__/10\.
/1 \__/7 \__/
\__/5 \__/11\.
/2 \__/8 \__/
\__/6 \__/12\.
/3 \__/9 \__/
\__/ \__/

EDIT: my hexes turned out crappy, I'm not good with the formatting :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!