Class cocos.tiles.HexMap

RegularTesselationMap --+
                        |
                       HexMap
Known Subclasses:
HexMapLayer

MapLayer with flat-top, regular hexagonal cells.

Calculated attributes:

edge_length -- length of an edge in pixels = int(th / math.sqrt(3)) tw -- with of a "tile" in pixels = edge_length * 2

Hexmaps store their cells in an offset array, column-major with y increasing up, such that a map:

  /d\ /h        /b\_/f\_/
\_/c\_/g        /a\_/e\_/
\_/ \_/

has cells = [['a', 'b'], ['c', 'd'], ['e', 'f'], ['g', 'h']]

(and this the cell at (0, 0) is 'a' and (1, 1) is 'd')

Methods

  __init__(self, id, th, cells, origin=None, properties=None)
  get_in_region(self, x1, y1, x2, y2)
Return cells (in [column][row]) that are within the pixel bounds specified by the bottom-left (x1, y1) and top-right (x2, y2) corners.
  get_at_pixel(self, x, y)
Get the Cell at pixel (x,y).
  get_neighbor(self, cell, direction)
Get the neighbor HexCell in the given direction which is one of self.UP, self.DOWN, self.UP_LEFT, self.UP_RIGHT, self.DOWN_LEFT or self.DOWN_RIGHT.
  get_neighbors(self, cell)
Get all neighbor cells for the nominated cell.
  get_cell(self, i, j)
Return Cell at cell pos=(i, j).
(Inherited from cocos.tiles.RegularTesselationMap)

Constants

  UP = 'up'
  DOWN = 'down'
  UP_LEFT = 'up left'
  UP_RIGHT = 'up right'
  DOWN_LEFT = 'down left'
  DOWN_RIGHT = 'down right'

Method Details

get_at_pixel

get_at_pixel(self, x, y)

Get the Cell at pixel (x,y).

Return None if out of bounds.

get_neighbor

get_neighbor(self, cell, direction)

Get the neighbor HexCell in the given direction which is one of self.UP, self.DOWN, self.UP_LEFT, self.UP_RIGHT, self.DOWN_LEFT or self.DOWN_RIGHT.

Return None if out of bounds.

get_neighbors

get_neighbors(self, cell)

Get all neighbor cells for the nominated cell.

Return a dict with the directions (self.UP, self.DOWN, etc) as keys and neighbor cells as values.