O'Reilly logo

Mazes for Programmers by Jamis Buck

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing a Hex Grid

So far we’ve made regular grids and circular grids. Our next goal is to create a grid of hexagons, also called a hex grid for short. We’ll approach this by first considering a single cell, with an eye to understanding how it relates spatially to its neighbors. From there, we’ll take that information and implement the grid itself.

The cells aren’t difficult to implement. The trickiest part is just understanding how they all fit together. Let’s look at a simple hex grid here:

images/hex-grid.png

From that, we can see that each hexagon neighbors up to six other hexagons, one for each of north, south, northwest, northeast, southwest, and southeast. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required