background preloader

Hexagonal Maps

Facebook Twitter

Hexagonal maps. Filed under: Programming · Date: Wed Oct 6 16:53:27 2004 Working with hexagonal maps is not much different to working with square grid maps. Look at the map to the right. It shows a hexagonal grid with labeled hexes. The labels tell the coordinates of each of the hex. Hexes with yellow background mark the X-coordinate; blue background marks Y-coordinate. Note that each hex on a row in alignment with the yellow row, have the same value for their X-coordinate. Calculating distance Calculating distance on hexagonal map is not difficult. dX = B.x - A.xdY = B.y - A.ydistance = (abs (dX) + abs (dY) + abs (dX - dY)) / 2 And here's an example. More information For more math on hexagonal maps, and other interesting reads, go to Amit Patel's game programming page.

Coordinates in Hexagon-Based Tile Maps. Introduction Tile Maps are often used for the graphics in two-dimensional games. Using tiles means that all graphics are combinations of smaller graphics, similar to mosaics. The advantage is a smaller need for memory. The tilesets are seldom bigger than a few hundred kilobytes and a map needs far less memory than a pre-rendered image; it needs only a pointer per field that identifies which tile is used. The simplest tiling system has plain squares. It's used in games like Warcraft II or the first C&C games. A hexagon based tile system offers a very nice solution. On the other side hexagon tiles are harder to work with, both for artists as well as for programmers. The mathematical structure of Hexagons First of all let's have a look at the mathematical characteristics of a hexagon.

In a hexagon all six sides have the same length s which meet at an angle of 120°. As in all other tile maps the information for hexagon based tile maps is stored in a two dimensional array. //pseudo Code!!! Clark Verbrugge’s Hex Grids. Update: Also see Amit’s guide to hex grids (2013), where I expand on the ideas Clark Verbrugge posted in this article. Copyright (c) Clark Verbrugge, 1997. [clump@cs.mcgill.ca] Copyright (c) Clark Verbrugge, 1996.

This article may be freely distributed as long as this attribution is included. This is version 3 of this document. The original version of the document can be found on Clark’s site. Contents: (0) Version History(1) The Hexagonal Coordinate System(2) Distance in Hexspace(3) Line of Sight (LOS) in Hexspace(4) How to Use Rectangular Arrays of Hexagons(5) Distance and LOS in a Rectangular Array of Hexagons(6) LOS by Intersection of Hexagons with a Straight Line(7) Euclidean Field of View (FOV) on a Hexagonal Grid(8) References (0) Version History 3 : Added this section, and sections on FOV and LOS by intersection 2.1: Fixed bug in Floor2 and Ceil2, which gave wrong values for negative inputs. 2 : Addition of material dealing with rectangular patches of hexagons. and thus, dist = 2; Isometric 'n' Hexagonal Maps Part I. Introduction WHOA! What do you know, I'm finally doing a tutorial on an actual Programming Topic.

I think the temperature in Hell must have dropped below 32. The source code examples in this tutorial will be both in Pascal, and C (wherever I can translate it). Since the techniques are cross platform, I won't be showing code on how to Blit the images to the screen. All of the tiles I use are 40x40, and all of the calculations are based on it. Depending on the size of bitmap you use, you may have to scale up or down. What the Hell are Isometric and Hexagonal Maps for? Isometric Maps are maps that use rhombuses instead of squares or rectangles.

Here is an Isometric Tile: (This tile is actually 40x40, but the rhombus only takes up the bottom 40x21) Hexagonal Maps are maps that use Hexagons (6 sided figures) instead of squares or rectangles. Here is a Hexagonal Tile: Forcing Isometric and Hexagonal Maps onto a Rectangular Grid Here's an IsoMap: Here's a HexMap: Plotting the Iso/Hex Tiles on the Map.