Creating a Hex Map

N

Niels Jensen

Hi All,

I'm desperately looking for help regarding the following:

I need to make a hexmap in it's own scrollable window on a form, when I
say hex map I mean a graphical hexagon surrounded by other hexagons the
same size. The program I'm writing imports region information i.e 10,13
would be a hexagon, 10 hex columns to the right and 13 hex rows down
from hex 1,1.

I have some source code for a Delphi add-in but having had zero
experience with Delphi, it's not a good place to start.

Can anyone point me in the right direction?

Please...

Niels
 
G

Gerald Hernandez

Intriguing. Sounds like a fun little project.
I would start out by asking what do you want to do with the map once you
have it. It sounds like a game map, but the question is more involved than
that.
Do you want to be able to graphically select hex cells?
Do you want to draw something else contained with the cells?
Do you want all sides to be equal like a regular circular inscribed polygon?
Or could the height/width aspect ratio be different?
Is the master grid a fixed size, or you want it to be dynamic?
Would the grid be rotatable?
What dotNet drawing methods are you familiar with?

The "easiest" solution would be based upon what you want to do with it.
If it is just draw a hex picture map, you could just create a cell block and
tile it. But not of much use.
If you want "intelligence", then you should probably go the vector route and
create hex cell Objects that render themselves to an intelligent "hex grid"
control.

Like most things, there are numerous ways to do this, but "begin with the
end in mind" to get the best results.

Gerald
 
O

One Handed Man \( OHM - Terry Burns \)

This is simple a vector drawing is it not, you could create an array for
each hexegon containing Six Points, these co-ordinates are then used to draw
a path on the graphics area of your control/form.

Dim myHexagon(8) As Point
Dim clientArea As Graphics

myHexagon(0) = New Point(50, 10)
myHexagon(1) = New Point(60, 10)
myHexagon(2) = New Point(70, 20)
myHexagon(3) = New Point(70, 30)
myHexagon(4) = New Point(60, 40)
myHexagon(5) = New Point(50, 40)
myHexagon(6) = New Point(40, 30)
myHexagon(7) = New Point(40, 20)
myHexagon(8) = New Point(50, 10)


clientArea = Me.CreateGraphics
clientArea.DrawLines(New Pen(Color.Red), myHexagon)

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
N

Niels Jensen

Gerald said:
Intriguing. Sounds like a fun little project.
I would start out by asking what do you want to do with the map once you
have it. It sounds like a game map, but the question is more involved than
that.
That's right - it is for a game, I'm looking to eventually import a text
based turn report into the program which will then draw out the map to
give me a graphical representation.
Do you want to be able to graphically select hex cells?
Yup - this will definitely be handy as that way you could click on a hex
and see which units are in it
Do you want to draw something else contained with the cells?
Yes again - each hex will have different terrain features such as
mountains or desert. Each hex can also contain thins like towns or
player built buildings
Do you want all sides to be equal like a regular circular inscribed polygon?
Or could the height/width aspect ratio be different?
All sides equal would be best
Is the master grid a fixed size, or you want it to be dynamic?
Would the grid be rotatable?
Rotating isn't necessary, zooming in and out however would be a benefit
but not necessarily needed
What dotNet drawing methods are you familiar with?
Here's the problem :) - next to nothing - yet. But with the help of the
net and other reference material I tend to pick these things up v.quickly
The "easiest" solution would be based upon what you want to do with it.
If it is just draw a hex picture map, you could just create a cell block and
tile it. But not of much use.
If you want "intelligence", then you should probably go the vector route and
create hex cell Objects that render themselves to an intelligent "hex grid"
control.

Like most things, there are numerous ways to do this, but "begin with the
end in mind" to get the best results.

Gerald

Thanks Gerald - you've definitely given me things to think about. now
to start looking for the material i need :)

Niels
 
N

Niels Jensen

One said:
This is simple a vector drawing is it not, you could create an array for
each hexegon containing Six Points, these co-ordinates are then used to draw
a path on the graphics area of your control/form.

Dim myHexagon(8) As Point
Dim clientArea As Graphics

myHexagon(0) = New Point(50, 10)
myHexagon(1) = New Point(60, 10)
myHexagon(2) = New Point(70, 20)
myHexagon(3) = New Point(70, 30)
myHexagon(4) = New Point(60, 40)
myHexagon(5) = New Point(50, 40)
myHexagon(6) = New Point(40, 30)
myHexagon(7) = New Point(40, 20)
myHexagon(8) = New Point(50, 10)


clientArea = Me.CreateGraphics
clientArea.DrawLines(New Pen(Color.Red), myHexagon)
Thanks for this, very kind of you - it'll give me someplace to start my
research - btw that's an octagon - a hexagon has six sides ;)

Niels
 
G

Gerald Hernandez

I'm giving this some thought.
To get everything you want might be quite complicated. Especially when just
learning.
However, that is half the fun, and what better way to learn, right?
I may be over complicating this, but I think you might want to create a user
control that will render everything. To accomodate the zooming and location
functions, your best bet would be to treat these cells as vector objects.
Meaning real Hexagons, instead of simple brush tiles.

One thing that will require special consideration is how you want to define
rows.
Since of course a Hex Grid zig-zags instead of being a classic grid.
Take a look at the attached 2 pictures.
In HexMap1, you have a defined set of rows. However, this is going to be a
mild pain to deal with the offsets. This is probably how the game works.
In HexMap 2, you have a mathematically easier approach, however your row
definition gets a little weird. If you are on an Odd Column, then your Rows
would be Odd. If on Even Column, then your Rows would be Even.

How does your game deal with this?

Gerald
 
N

Niels Jensen

Gerald said:
I'm giving this some thought.
To get everything you want might be quite complicated. Especially when just
learning.
However, that is half the fun, and what better way to learn, right?
I may be over complicating this, but I think you might want to create a user
control that will render everything. To accomodate the zooming and location
functions, your best bet would be to treat these cells as vector objects.
Meaning real Hexagons, instead of simple brush tiles.

This does sound more complicated - but I'm a firm believer that if you
dive in at the deep end you'll always end up with what you want - minus
a few handfuls of hair :)

So, I take it using vector objects is quite a bit more complicated than
Terry Burns solution?...
One thing that will require special consideration is how you want to define
rows.
Since of course a Hex Grid zig-zags instead of being a classic grid.
Take a look at the attached 2 pictures.
In HexMap1, you have a defined set of rows. However, this is going to be a
mild pain to deal with the offsets. This is probably how the game works.
In HexMap 2, you have a mathematically easier approach, however your row
definition gets a little weird. If you are on an Odd Column, then your Rows
would be Odd. If on Even Column, then your Rows would be Even.

How does your game deal with this?

The game has the following description in it's rules - The game's called
"Atlantis":

----
Since Atlantis is made up of hexagonal regions, the coordinate system is
not always exactly intuitive. Here is the layout of Atlantis regions:

____ ____
/ \ / \
/(0,0) \____/(2,0) \____/
\ / \ / \ N
\____/(1,1) \____/(3,1) \_ |
/ \ / \ / |
/(0,2) \____/(2,2) \____/ |
\ / \ / \ W-O-E
\____/(1,3) \____/(3,3) \_ |
/ \ / \ / S
/(0,4) \____/(2,4) \____/
\ / \ / \
\____/ \____/
/ \ / \

Note that the are "holes" in the coordinate system; there is no region
(1,2), for instance. This is due to the hexagonal system of regions.
---
So it would seem that any hexes with an even column will only have even
rows and likewise any odd column hexes only have odd numbered rows. It
helps knowing that a map will never use negative numbers so a simple
mathematical equation should be able to work out how to place the hexes.

I can also provide an example on how the report processes it's region
information. As it stands, my basic program at the moment is able to
process the reports and categorize them into relevant groups. I'm
thinking of using ADO to store the turn information, this will allow me
to use SQL to filter out specific region information for each hex.

Niels
 
G

Gerald Hernandez

Ah, it looks like it resembles the second example I sent.
This is slightly surprising. Good news is that the math is a little easier,
just slightly less intuitive to the user.

Actually, the vector method will essentially be the same as OHM's
suggestion.
But instead of drawing just 1, you would just write formulas to build the
whole grid.
There are many ways to derive the numbers for the points, but in the end you
will just pass an array of points to draw the Hex cell.

I'm giving the overall grid some thought and how that will work with
scaling.
Drawing 1 is easy, but making it interactive is more fun.

My suggestion is to deal with a "grid" where you know the center of the Hex
cells.
Then derive the polygon points from the center point.
This way you would also know where to draw other cool things in the middle
of the cell. ;-)

Gotta run at the moment, but I'll throw up a couple of formulas when I get a
chance.

Gerald
 
O

One Handed Man \( OHM - Terry Burns \)

LOL, sorry, a moment of madness !, I allways wondered why I wasn't any good
at DIY

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
G

Gerald Hernandez

It is probably your news reader stripping the attachement for safety
reasons.
Kinda cool (NOT) that Microsoft's "fix" for security holes in their software
is to prevent you from getting to things you might want, instead of actually
fixing the flaw.
If you are using Outlook Express, try going to:
Tools->Options->Security tab,
Virus Protection,
and uncheck the "Do not allow attachments to be saved or opened that could
potentially be a virus."

Then try checking the message again.
Otherwise, email me your email address at Cablewizard@[email protected]
by removing the @Spam_Remove part, and I will try mailing to you directly.

Gerald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top