Simplify hex map creation.

This commit is contained in:
Dorian 2017-07-27 17:28:51 -04:00
parent b7346b713a
commit 2aaa27a824
1 changed files with 13 additions and 21 deletions

View File

@ -33,32 +33,24 @@ class HexMap(Widget):
for y in range(tiles_in_col):
if y % 2 == 0:
hex_color = "#0000dd55"
even_row = True
tiles_in_row = tiles_in_even_row
else:
hex_color = "#dd000055"
even_row = False
tiles_in_row = tiles_in_odd_row
even_row = y % 2 == 0
hex_color = "#0000dd55" if even_row else "#dd000055"
tiles_in_row = tiles_in_even_row if even_row else tiles_in_odd_row
y_position = y * HEX_SIZE * VERTICAL_BUFFER
for x in range(tiles_in_row):
Color(*get_color_from_hex(hex_color))
if even_row:
Ellipse(
pos=(x * HEX_SIZE * HORIZONTAL_BUFFER, y * HEX_SIZE * VERTICAL_BUFFER),
segments=6,
size=(HEX_SIZE, HEX_SIZE),
)
x_position = x * HEX_SIZE * HORIZONTAL_BUFFER
if not even_row:
x_position += 0.5 * HEX_SIZE * HORIZONTAL_BUFFER
else:
Ellipse(
pos=((x * HEX_SIZE * HORIZONTAL_BUFFER) + (0.5 * HEX_SIZE * HORIZONTAL_BUFFER),
y * HEX_SIZE * VERTICAL_BUFFER),
segments=6,
size=(HEX_SIZE, HEX_SIZE),
)
Ellipse(
pos=(x_position, y_position),
segments=6,
size=(HEX_SIZE, HEX_SIZE),
)
class HexMapApp(App):