Rough working builder of hex map.

This commit is contained in:
Dorian 2017-07-27 08:28:46 -04:00
parent 5494e18ea5
commit 3ae9251780
1 changed files with 43 additions and 1 deletions

View File

@ -1,9 +1,51 @@
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
MAP_EDGE = 20
HEX_SIZE = 100
NUMBER_OF_HEXES = 2
class HexMap(Widget):
pass
def __init__(self, **kwargs):
super(HexMap, self).__init__(**kwargs)
self.redraw_scene()
# It is crucial to redraw the scene whenever the scene or position changes.
self.bind(size=self.redraw_scene, pos=self.redraw_scene)
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"))
Rectangle(
pos=(MAP_EDGE, MAP_EDGE),
size=(self.width - (2 * MAP_EDGE), self.height - (2 * MAP_EDGE)))
# Draw a hexagon in a decent spot.
tiles_in_row = (self.width - MAP_EDGE * 2) / HEX_SIZE
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 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),
)
class HexMapApp(App):