Kotlin implementation of hexagonal grids using LibGDX
Alternatives To Khexgrid
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
5 years ago1May 11, 20162apache-2.0Java
:octocat: Simple map generators for Java applications.
7 months agoapache-2.0Kotlin
Kotlin implementation of hexagonal grids using LibGDX
2 years agogpl-3.0Java
A multiplayer grid based strategy game powered by libGDX
Alternatives To Khexgrid
Select To Compare

Alternative Project Comparisons


Kotlin implementation of hexagonal grids using LibGDX.

Allows for grids of any size and shape - square, rectangular, triangular, or even irregular. Supports both pointy-top and flat-top hexes.

Based on Red Blob Games' fantastic guide on hexagonal grids.


Locations in the map are represented as CubeCoordinates. A CubeCoordinate has many handy operations built-in, but knows nothing of the external map structure. These objects are immutable by design, but can readily be converted to several other types, such as OffsetCoordinates or vectors.

A HexagonalMap consists of a series of CubeCoordinates mapped to HexagonalTiles at those locations. The corresponding HexagonalLayout and HexagonalOrientation can be used to control the position and appearance of the tiles. A HexagonalTile is composed of a location and a Terrain, which defines rules for tiles such as movement cost and visibility.

A map can be drawn using a LayeredRenderer. The renderer will draw any Layers provided. It will also handle culling the tiles that are drawn to the camera's viewable area to reduce unnecessary drawing. Some simple Layer implementations are also included.

Example Usage

Create map

val tiles = (0 until rows).flatMap { row ->
    (0 until columns).map { column ->
        val coordinate = OffsetCoordinate(column, row, OffsetCoordinateType(HexagonalOrientation.POINTY_TOP)).toCubeCoordinate()
        coordinate to HexagonalTile(coordinate, getTerrain(column, row))
val map = HexagonalMap(layout, tiles)

Find all valid locations within 10 tiles of a location (CubeCoordinate)

location.withinRange(10).filter { map.isValidLocation(it) }

Find all locations that are 3 tiles away from a location


Find locations that can be moved to at a movement cost of 5 or less

map.getReachableLocations(location, 5)

Find visible locations (i.e. tiles with unobstructed view) within 7 tiles of location

map.getVisibleLocations(location, 7)

Draw map to screen

val hexRenderer = HexagonalRenderer(map, Vector2(32, 32))
val renderer = LayeredRenderer(map, listOf(
    TerrainLayer(map, hexRenderer, terrainViews),
    TileOutlineLayer(hexRenderer, shapeRenderer)
), camera)
Popular Libgdx Projects
Popular Grid Projects
Popular Games Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.