doric-engine/main.py

49 lines
1.6 KiB
Python
Raw Normal View History

from kivy import app, properties
2016-06-04 14:31:07 -04:00
from kivy.uix.floatlayout import FloatLayout
from kivy.graphics import Color, Rectangle
from hexmap import HexMapCell
2016-06-04 14:59:40 -04:00
2016-06-04 14:59:40 -04:00
class StrategyGame(FloatLayout):
main_map = properties.ObjectProperty(None)
status = properties.ObjectProperty(None)
map_rows = properties.NumericProperty(0)
map_cols = properties.NumericProperty(0)
def __init__(self, **kwargs):
super(StrategyGame, self).__init__(**kwargs)
number_of_regions = self.map_rows * self.map_cols
for region in range(0, number_of_regions):
row = region / self.map_cols
col = region % self.map_cols
# Add hex cells to make up the map.
2016-07-16 15:11:41 -04:00
hex_cell = HexMapCell(row, col)
2016-07-16 22:17:23 -04:00
hex_cell.disabled = True
self.main_map.add_widget(hex_cell)
# Add overlay conditionally.
if (row % 6 == 1 and col % 2 == 1) or (row % 6 == 4 and col % 2 == 0) and (col > 0):
2016-07-16 22:17:23 -04:00
hex_cell.disabled = False
hex_cell.visible_on_map = True
# Bind the cell code so as to update its position and size when the parent widget resizes.
2016-06-05 01:20:00 -04:00
hex_cell.bind(pos=hex_cell.update_pos, size=hex_cell.update_pos)
def update_selected_cell(self, coords, terrain_colour, *args):
self.status.text = 'Coords: ({}, {})'.format(coords[0], coords[1])
with self.status.canvas.before:
Color(*terrain_colour)
Rectangle(pos=self.status.pos, size=self.status.size)
return True
class StrategyGameApp(app.App):
2016-06-04 14:31:07 -04:00
def build(self):
2016-06-04 14:59:40 -04:00
return StrategyGame()
2016-06-04 14:31:07 -04:00
if __name__ == '__main__':
2016-06-04 14:59:40 -04:00
StrategyGameApp().run()