Draw the hex grid
This commit is contained in:
parent
9cc0f805c8
commit
dbc704226a
61
main.py
61
main.py
|
@ -5,7 +5,7 @@ from kivy import properties
|
||||||
from kivy import graphics
|
from kivy import graphics
|
||||||
from kivy.uix import label
|
from kivy.uix import label
|
||||||
from kivy.uix.floatlayout import FloatLayout
|
from kivy.uix.floatlayout import FloatLayout
|
||||||
|
import math
|
||||||
|
|
||||||
MapCoords = collections.namedtuple('MapCoords', ['row', 'col'])
|
MapCoords = collections.namedtuple('MapCoords', ['row', 'col'])
|
||||||
|
|
||||||
|
@ -22,42 +22,45 @@ class StrategyGame(FloatLayout):
|
||||||
for region in xrange(0, number_of_regions):
|
for region in xrange(0, number_of_regions):
|
||||||
row = region / self.map_cols
|
row = region / self.map_cols
|
||||||
col = region % self.map_cols
|
col = region % self.map_cols
|
||||||
self.main_map.add_widget(HexMapCell(row=row, col=col))
|
self.main_map.add_widget(self.pick_hex_cell(row=row, col=col))
|
||||||
|
|
||||||
|
|
||||||
|
def pick_hex_cell(self, row, col):
|
||||||
|
row_mod = row % 6
|
||||||
|
if col % 2 == 0:
|
||||||
|
if row_mod == 0:
|
||||||
|
return BU()
|
||||||
|
elif row_mod in (1, 2):
|
||||||
|
return L()
|
||||||
|
elif row_mod == 3:
|
||||||
|
return TD()
|
||||||
|
elif row_mod in (4, 5):
|
||||||
|
return R()
|
||||||
|
else:
|
||||||
|
if row_mod == 0:
|
||||||
|
return TD()
|
||||||
|
elif row_mod in (1, 2):
|
||||||
|
return R()
|
||||||
|
elif row_mod == 3:
|
||||||
|
return BU()
|
||||||
|
elif row_mod in (4, 5):
|
||||||
|
return L()
|
||||||
|
|
||||||
|
|
||||||
class HexMapCell(label.Label):
|
class HexMapCell(label.Label):
|
||||||
def __init__(self, row=0, col=0, **kwargs):
|
def __init__(self, row=0, col=0, **kwargs):
|
||||||
self.region_in_map = MapCoords(row, col)
|
self.region_in_map = MapCoords(row, col)
|
||||||
super(HexMapCell, self).__init__(**kwargs)
|
super(HexMapCell, self).__init__(**kwargs)
|
||||||
self.draw_hex_edge()
|
|
||||||
|
|
||||||
def draw_hex_edge(self):
|
class BU(HexMapCell):
|
||||||
edge = ''
|
pass
|
||||||
if self.region_in_map.col % 2 == 0:
|
class TD(HexMapCell):
|
||||||
row_mod = self.region_in_map.row % 6
|
pass
|
||||||
if row_mod == 0:
|
class L(HexMapCell):
|
||||||
edge = 'BU'
|
pass
|
||||||
with self.canvas:
|
class R(HexMapCell):
|
||||||
graphics.Color(1, 1, 1, 1)
|
pass
|
||||||
graphics.Line(points=[self.x, self.y, self.width + self.x, self.height + self.y])
|
|
||||||
elif row_mod in (1, 2):
|
|
||||||
edge = 'L '
|
|
||||||
elif row_mod == 3:
|
|
||||||
edge = 'TD'
|
|
||||||
elif row_mod in (4, 5):
|
|
||||||
edge = ' R'
|
|
||||||
else:
|
|
||||||
row_mod = self.region_in_map.row % 6
|
|
||||||
if row_mod == 0:
|
|
||||||
edge = 'TD'
|
|
||||||
elif row_mod in (1, 2):
|
|
||||||
edge = ' R'
|
|
||||||
elif row_mod == 3:
|
|
||||||
edge = 'BU'
|
|
||||||
elif row_mod in (4, 5):
|
|
||||||
edge = 'L '
|
|
||||||
|
|
||||||
self.text = edge
|
|
||||||
|
|
||||||
class StrategyGameApp(App):
|
class StrategyGameApp(App):
|
||||||
def build(self):
|
def build(self):
|
||||||
|
|
|
@ -22,3 +22,32 @@
|
||||||
DebugLabel:
|
DebugLabel:
|
||||||
text: 'mini-map'
|
text: 'mini-map'
|
||||||
size_hint: 1, .33
|
size_hint: 1, .33
|
||||||
|
|
||||||
|
<BU>:
|
||||||
|
canvas:
|
||||||
|
Color:
|
||||||
|
rgba: (1,1,1,1)
|
||||||
|
Line:
|
||||||
|
points: (self.x, self.y, self.right, self.top)
|
||||||
|
width: 2
|
||||||
|
<TD>:
|
||||||
|
canvas:
|
||||||
|
Color:
|
||||||
|
rgba: (1,1,1,1)
|
||||||
|
Line:
|
||||||
|
points: (self.x, self.top, self.right, self.y)
|
||||||
|
width: 2
|
||||||
|
<L>:
|
||||||
|
canvas:
|
||||||
|
Color:
|
||||||
|
rgba: (1,1,1,1)
|
||||||
|
Line:
|
||||||
|
points: (self.x, self.y, self.x, self.top)
|
||||||
|
width: 2
|
||||||
|
<R>:
|
||||||
|
canvas:
|
||||||
|
Color:
|
||||||
|
rgba: (1,1,1,1)
|
||||||
|
Line:
|
||||||
|
points: (self.right, self.y, self.right, self.top)
|
||||||
|
width: 2
|
||||||
|
|
Loading…
Reference in New Issue