Understanding hexagonal tiles

You should already know Tile Maps: they are often used for the level design in two-dimensional games.

The most used (and simplest) tiling system has squares. Tileball is an example of a game made with this method.

Even if there are a lot of games using this tiling system, it’s easy to find its limit. All movements are restricted to four directions: up, down, left, right.

Some more complex games require a more complex tiling system.

That’s why I am introducing you the hexagon based tile system (hex maps from now on)

Wkipedia explains us the advantage of a hex map over a square grid map is that the distance between the center of each hex cell and the center of all six adjacent hex cells remains constant. Compare this to a square grid map where the distance from the center of each square cell (of side length x) to the center of its four diagonal adjacent cells is longer than the distance to the center of its four cardinal adjacent cells (x√2 instead of x).

It’s nothing new, because you may find hex maps in Gettysburg, a board game released in 1958 (yes: half a century ago), as you can see in the photo showing the 125th Anniversary Edition of the game

Gettysburg

Back to computer games, you can play The Battle for Wesnoth, a free turn based strategy game designed in June 2003 by David White using hex maps

Wesnoth

Now that we know hex maps are important, let’s see what is an hexagon: in geometry, a hexagon is a polygon with six edges and six vertices. When the six sides of an hexagon have the same length, we are talking about a regular hexagon.

Regular hexagon properties

Hexagon

As you can see, if all sides have the same lenght, we can say the total length of the hexagon is:

Total length = Side + 2*(Side*sin(30°)) = Side + 2*0.5 = 2*Side

And the total height is:

Total height = 2*(Side*cos(60°))

Now, it’s important to know we can tile hexagons in two ways: I don’t think someone already gave a name to the ways you can tile hexagons, so I will call H-hex map a map made tiling hexagons horizontally and V-hex map a map made tiling hexagons vertically, just like in the picture.

Hexagon tiling

Obviously, each map has its own way to manage tiles.

And that’s all… obviously I am about to code everything in Actionscript, meanwhile if you have some code to share, show the world you are awesome

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 4.80 out of 5)
Loading ... Loading ...
If you found this post useful, please consider a small donation.

15 Responses to “Understanding hexagonal tiles”

  1. Keiran on April 16th, 2008 3:25 pm

    interesting concept

  2. Jack Hopkisn on April 16th, 2008 6:08 pm

    exellent! Perfect timing as always as i am currently struggling with it ;)

  3. JDog on April 16th, 2008 6:33 pm

    This is great, will this be added to the Boxhead game tutorials ? Since boxhead has 8 directions of movement, 6 is close.

  4. styxtwo on April 16th, 2008 7:45 pm

    JDog, the 8 and 6 directions are very different. the tiles used in the boxhead games are not hex tiles and therefore do not have the difficulties that come with placing them.
    what you are talking about is walking directions, that is a whole different topic :)

  5. JDog on April 16th, 2008 8:29 pm

    Oh heck, I knew that, I was just wondering. Its isometric isn’t it….sorry I was being silly. An isometric tile engine would be cool…

  6. Olivier on April 16th, 2008 8:46 pm

    I not to long ago made hexagons tile (tho with as2) for a flash website, i’d like to see how you do this, i wrote a very simple function which drew horizontal lines of hexagons, and per line the starting position jumped left or right half a hexagon. Im sure there are better mathematical ways, enlighten me :)

  7. JDog on April 17th, 2008 5:50 pm

    Emanuele you forgot about Hexic, the best game in the world to feature Hexagons !

  8. engin on May 8th, 2008 1:48 pm

    Your hexagon diagram is wrong.
    Side * cos(60) should be Side * cos(30) or Side * sin(60) I think (:

    Thx for the excellent tutorials btw.

  9. xklamatok on August 13th, 2008 1:23 am

    another way to figure out the height of a hexagon (V-Hex style as per your example):
    Pythagoras sez:
    a^2 + b^2 = c^2
    we know c which is the radius and a which is half the radius.
    So we are looking for sqrt(c^2 – a^2) or sqrt(3/4)*radius.
    i guess one of them might be faster, like a 2.345 milliseconds :D

  10. Douglas Huskins on October 16th, 2008 3:03 am

    About 10 years ago, I wrote a collection of functions that would help a person navigate hex maps. The functions included: Identifying the adjacent hexes, identifying the shortest path between two hexes, the relative position of a hex from the perspective of another hex and the distance between two hexes.

    Let me see if I can find that code and I will send it to you.

  11. Terry on March 29th, 2009 10:10 am

    Your stuff on hexagons is interesting. Maybe you will like the way that I have used the concept for my Hexidek. If you google the word, you ought to find some pics online.

Leave a Reply




Trackbacks

  1. Odds & Ends: April 17, 2008 on April 18th, 2008 1:20 am

    [...] A short overview of hexagonal tiles, or “hexes” to you wargamers in the crowd, from “italian geek and PROgrammer” Emanuele Feronato [...]

  2. Hex maps creation and rollover : Emanuele Feronato - italian geek and PROgrammer on April 20th, 2008 2:18 pm

    [...] article does not cover all hex maps, just horizontal ones. Read Understanding hexagonal tiles to know something more about hex [...]

  3. Developing hex map concept : Emanuele Feronato on October 22nd, 2008 9:36 pm

    [...] months ago I released some tutorials about hexagonal tiles (and I developed an Halloween game based upon Hex maps creation and rollover and Finding adjacent [...]

  4. Halloween Couples : Emanuele Feronato on November 2nd, 2008 9:27 pm

    [...] basics of hexagonal environments are explained in Understanding hexagonal tiles, Finding adjacent cells in an hex map – part 1 and [...]

flash games company