Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Noise4j | 64 | 5 years ago | 1 | May 11, 2016 | 2 | apache-2.0 | Java | |||
:octocat: Simple map generators for Java applications. | ||||||||||
Khexgrid | 12 | 7 months ago | apache-2.0 | Kotlin | ||||||
Kotlin implementation of hexagonal grids using LibGDX | ||||||||||
Zoned | 8 | 2 years ago | gpl-3.0 | Java | ||||||
A multiplayer grid based strategy game powered by libGDX |
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 CubeCoordinate
s. 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 OffsetCoordinate
s or vectors.
A HexagonalMap
consists of a series of CubeCoordinate
s mapped to HexagonalTile
s 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 Layer
s 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.
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))
}
}.toMap()
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
location.ring(3)
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)
renderer.render(batch)