diff --git a/hexmap.py b/hexmap.py index 26c80c9..e8a9585 100644 --- a/hexmap.py +++ b/hexmap.py @@ -12,33 +12,30 @@ from terrain import choose_random_terrain, Terrains MapCoords = collections.namedtuple('MapCoords', ['row', 'col']) -class HexMapCell(Label): +class Tile(Label): def __init__(self, row=0, col=0, **kwargs): - super(HexMapCell, self).__init__(**kwargs) + super(Tile, self).__init__(**kwargs) self.coords = MapCoords(row, col) # set the cube coordinates of the hexagon # as [x, y, z] - self.cube_coords = self.even_r_to_cube(self.coords.row // 3, self.coords.col // 2) + self.cube_coords = self.even_r_to_cube(self.coords.row, self.coords.col) self.selected = False # Pick a random terrain for each hex. self.terrain = choose_random_terrain() self.terrain_colour = kivy.utils.get_color_from_hex(Terrains[self.terrain]['color']) - # Determine the location of the solid hexagon cell. Needs to be offset from the centre of the hex. radius = self.height / 2 - solid_size = (self.height, self.height) - self.bind(pos=self.update_pos, size=self.update_pos) with self.canvas.after: # Create the solid background of the hexagon, from the bottom left coordinate of the hex. Color(*self.terrain_colour) - self.solid = Ellipse(pos=(self.x, self.y), size=solid_size, segments=6) + self.solid = Ellipse(pos=(self.x, self.y), size=(self.height, self.height), segments=6) # Create the outline of hexagon, based off the centre of the hex. Color(*kivy.utils.get_color_from_hex('#000000')) - self.ell = Line(circle=(self.x, self.y, radius, 0, 360, 6), width=2) + self.ell = Line(circle=(self.center_x, self.center_y, radius, 0, 360, 6), width=2) Color(0, 0, 0, 1) self.coord_label = Label( @@ -79,11 +76,13 @@ class HexMapCell(Label): return "{}\n{} \n {}".format(self.even_r_coordinate_text(), self.cube_coordinate_text(), self.terrain) def update_pos(self, instance, value): - # Determine the location of the solid hexagon cell. Needs to be offset from the centre of the hex. + + self.canvas.clear() + radius = self.height / 2 # Resize the outline of the cell. - self.ell.circle = (self.x, self.y, radius, 0, 360, 6) + self.ell.circle = (self.center_x, self.center_y, radius, 0, 360, 6) # Resize the actual cell. self.solid.pos = (self.x, self.y) @@ -93,7 +92,7 @@ class HexMapCell(Label): self.coord_label.center_y = self.center_y def on_touch_down(self, touch): - if super(HexMapCell, self).on_touch_down(touch): + if super(Tile, self).on_touch_down(touch): return False coord_x, coord_y = self.even_r_coords @@ -101,7 +100,7 @@ class HexMapCell(Label): with self.canvas.after: Color(*kivy.utils.get_color_from_hex('#000000')) radius = self.height / 2 - self.ell = Line(circle=(self.x, self.y, radius, 0, 360, 6), width=2) + self.ell = Line(circle=(self.center_x, self.center_y, radius, 0, 360, 6), width=2) if not self.collide_with_bounding_circle(touch.x, touch.y): return False @@ -115,7 +114,7 @@ class HexMapCell(Label): # TODO Will refactor to have separate on_touch_up for selected target hex instead. Color(*kivy.utils.get_color_from_hex('#FF0000')) radius = self.height / 2 - self.ell = Line(circle=(self.x, self.y, radius, 0, 360, 6), width=2) + self.ell = Line(circle=(self.center_x, self.center_y, radius, 0, 360, 6), width=2) self.parent.parent.game.update_selected_cell(self) return True diff --git a/main.py b/main.py index 34887d1..727f334 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ from kivy.uix.label import Label from kivy.uix.boxlayout import BoxLayout from kivy.graphics import Color, Rectangle -from hexmap import HexMapCell +from hexmap import Tile class HexSpace(Label): @@ -28,7 +28,7 @@ class StrategyGame(BoxLayout): hex_map_row.add_widget(HexSpace()) for col in range(0, self.map_cols): - map_tile = HexMapCell(row=row, col=col) + map_tile = Tile(row=row, col=col) hex_map_row.add_widget(map_tile) if row % 2 == 0: