Finally a working hex map that expands.

This commit is contained in:
Dorian 2017-07-27 08:47:27 -04:00
parent 3ae9251780
commit 937d6b8b9b
1 changed files with 37 additions and 24 deletions

View File

@ -1,13 +1,14 @@
from kivy.app import App
from kivy.core.window import Window
from kivy.graphics import *
from kivy.uix.widget import Widget
from kivy.utils import get_color_from_hex, get_random_color
from kivy.utils import get_color_from_hex
MAP_EDGE = 20
HEX_SIZE = 100
NUMBER_OF_HEXES = 2
HORIZONTAL_BUFFER = 0.9
VERTICAL_BUFFER = 0.8
class HexMap(Widget):
@ -20,32 +21,44 @@ class HexMap(Widget):
def redraw_scene(self, *args):
with self.canvas:
# Draw border around entire field.
Color(*get_color_from_hex("#abcd00"))
Rectangle(pos=(0, 0), size=(self.width, self.height))
Color(*get_color_from_hex("#000000"))
# Clear scene
Color(*get_color_from_hex("#000000ff"))
Rectangle(
pos=(MAP_EDGE, MAP_EDGE),
size=(self.width - (2 * MAP_EDGE), self.height - (2 * MAP_EDGE)))
pos=(0, 0),
size=(self.width, self.height)
)
# Draw a hexagon in a decent spot.
tiles_in_row = (self.width - MAP_EDGE * 2) / HEX_SIZE
tiles_in_row = int(self.width / (HEX_SIZE * HORIZONTAL_BUFFER))
# TODO: Add a tiles in alternating row.
tiles_in_col = int(self.height / (HEX_SIZE * VERTICAL_BUFFER))
for i in range(tiles_in_row):
Color(*get_color_from_hex("#00dd0055"))
Ellipse(
pos=(MAP_EDGE + i * HEX_SIZE * 0.9, MAP_EDGE),
segments=6,
size=(HEX_SIZE, HEX_SIZE),
)
for y in range(tiles_in_col):
for i in range(tiles_in_row):
Color(*get_color_from_hex("#00dd0055"))
Ellipse(
pos=(MAP_EDGE + (i * HEX_SIZE * 0.9) + (0.5 * HEX_SIZE * 0.9), MAP_EDGE + (HEX_SIZE * 0.8)),
segments=6,
size=(HEX_SIZE, HEX_SIZE),
)
if y % 2 == 0:
hex_color = "#0000dd55"
even_row = True
else:
hex_color = "#dd000055"
even_row = False
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),
)
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),
)
class HexMapApp(App):