Public Group

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

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

## 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 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 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 on other sites
thanks for replaying!

[Edited by - code_nerd on August 24, 2005 6:51:14 PM]

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 9
• 19
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633380
• Total Posts
3011578
• ### Who's Online (See full list)

There are no registered users currently online

×