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

Started by
2 comments, last by code_nerd 18 years, 8 months ago
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!
Advertisement
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.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

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 :)
-------------Become part of developing the specifications of a new language. Visit CodeBASIC.org
thanks for replaying!

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

This topic is closed to new replies.

Advertisement