Merge branch 'llfkj' of https://github.com/llf-amy/gamecamp into llfkj
This commit is contained in:
commit
e367ee54e4
27
hexmap.py
27
hexmap.py
|
@ -12,6 +12,8 @@ class HexMapCell(Label):
|
|||
## 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.selected = False
|
||||
self.visible_on_map = False
|
||||
|
||||
def even_r_to_cube(self, row, col):
|
||||
'''compute cube coordinates from even-r hex coordinates'''
|
||||
|
@ -63,3 +65,28 @@ class HexMapCell(Label):
|
|||
self.coord_label.center_x = self.x
|
||||
self.coord_label.center_y = self.y
|
||||
|
||||
|
||||
def on_touch_down(self, touch):
|
||||
if super(HexMapCell, self).on_touch_down(touch):
|
||||
return False
|
||||
|
||||
if not self.visible_on_map:
|
||||
return False
|
||||
|
||||
if not self.collide_point(touch.x, touch.y):
|
||||
with self.canvas.after:
|
||||
Color(*kivy.utils.get_color_from_hex('#A1A5AA'))
|
||||
radius = 2 * self.height
|
||||
self.ell = Line(circle=(self.x, self.y, radius, 0, 360, 6), width=2)
|
||||
return False
|
||||
|
||||
with self.canvas.after:
|
||||
if 'button' in touch.profile and touch.button == 'left':
|
||||
Color(*kivy.utils.get_color_from_hex('#00FF00'))
|
||||
|
||||
if 'button' in touch.profile and touch.button == 'right':
|
||||
# TODO Will refactor to have separate on_touch_up for selected target hex instead.
|
||||
Color(*kivy.utils.get_color_from_hex('#FF0000'))
|
||||
radius = 2 * self.height
|
||||
self.ell = Line(circle=(self.x, self.y, radius, 0, 360, 6), width=2)
|
||||
return True
|
||||
|
|
5
main.py
5
main.py
|
@ -26,7 +26,7 @@ class StrategyGame(FloatLayout):
|
|||
|
||||
# Add overlay conditionally.
|
||||
if (row % 6 == 1 and col % 2 == 1) or (row % 6 == 4 and col % 2 == 0) and (col > 0):
|
||||
print('({}, {})'.format(row, col))
|
||||
hex_cell.visible_on_map = True
|
||||
|
||||
# Determine the location of the solid hexagon cell. Needs to be offset from the centre of the hex.
|
||||
radius = 2 * hex_cell.height
|
||||
|
@ -37,7 +37,7 @@ class StrategyGame(FloatLayout):
|
|||
with hex_cell.canvas.after:
|
||||
|
||||
# Create the outline of hexagon, based off the centre of the hex.
|
||||
Color(1, 0, 1, 1)
|
||||
Color(*kivy.utils.get_color_from_hex('#A1A5AA'))
|
||||
hex_cell.ell = Line(circle=(hex_cell.x, hex_cell.y, radius, 0, 360, 6), width=2)
|
||||
|
||||
# Create the solid background of the hexagon, from the bottom left coordinate of the hex.
|
||||
|
@ -54,6 +54,7 @@ class StrategyGame(FloatLayout):
|
|||
hex_cell.bind(pos=hex_cell.update_pos, size=hex_cell.update_pos)
|
||||
|
||||
|
||||
|
||||
class StrategyGameApp(app.App):
|
||||
def build(self):
|
||||
return StrategyGame()
|
||||
|
|
|
@ -31,16 +31,6 @@
|
|||
size_hint: 1, .33
|
||||
background_color: .75, .71, .99, 1
|
||||
|
||||
<Hex@Label>:
|
||||
pos_hint: {'center_x':.5, 'center_y':.5}
|
||||
canvas.after:
|
||||
Color:
|
||||
rgba: 1,1,1,1
|
||||
Ellipse:
|
||||
segments: 6
|
||||
pos: self.pos
|
||||
size: min(self.width, self.height), min(self.width, self.height)
|
||||
|
||||
<HexMapCell>:
|
||||
size_hint: 1, None
|
||||
height: self.width / math.sqrt(3)
|
Loading…
Reference in New Issue