From d85027abdc85ecf471b5129b6f07af9cf485b6ee Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Wed, 9 Nov 2016 22:36:05 -0500 Subject: [PATCH] Add requirements and enable simple Python 2/3 compatibility. --- hexmap.py | 30 ++++++++++++++++++++++++++++-- launch_app.sh | 2 ++ main.py | 31 +------------------------------ strategygame.kv | 4 ++-- 4 files changed, 33 insertions(+), 34 deletions(-) create mode 100644 launch_app.sh diff --git a/hexmap.py b/hexmap.py index a68a6d8..4787b55 100644 --- a/hexmap.py +++ b/hexmap.py @@ -3,10 +3,12 @@ from math import ceil from kivy.logger import Logger from kivy.uix.label import Label -from kivy.graphics import Color, Line +from kivy.graphics import Color, Line, Ellipse import kivy.utils from kivy.vector import Vector +from terrain import choose_random_terrain, Terrains + MapCoords = collections.namedtuple('MapCoords', ['row', 'col']) @@ -19,8 +21,32 @@ class HexMapCell(Label): self.cube_coords = self.even_r_to_cube(self.coords.row / 3, self.coords.col / 2) self.selected = False self.visible_on_map = False + + # Pick a random terrain for each hex. + self.terrain = choose_random_terrain() self.terrain_colour = Color(0, 0, 0, 1) - self.terrain = '' + + # Determine the location of the solid hexagon cell. Needs to be offset from the centre of the hex. + radius = self.height / 2 + solid_x = self.x - self.height + solid_y = self.y - self.height + solid_size = (self.height, self.height) + + with self.canvas.after: + # Create the solid background of the hexagon, from the bottom left coordinate of the hex. + self.terrain_colour = kivy.utils.get_color_from_hex(Terrains[self.terrain]['color']) + Color(*self.terrain_colour) + self.solid = Ellipse(pos=(solid_x, solid_y), size=solid_size, segments=6) + + # Create the outline of hexagon, based off the centre of the hex. + Color(*kivy.utils.get_color_from_hex('#000000')) + self.ell = Line(circle=(self.x, self.y, radius, 0, 360, 6), width=2) + + Color(0, 0, 0, 1) + self.coord_label = Label( + text=self.map_display_text(), + center_x=self.x, + center_y=self.y) @staticmethod def even_r_to_cube(row, col): diff --git a/launch_app.sh b/launch_app.sh new file mode 100644 index 0000000..d7e1576 --- /dev/null +++ b/launch_app.sh @@ -0,0 +1,2 @@ +#!/bin/sh +python main.py --size=1280x700 diff --git a/main.py b/main.py index 9f47a5a..c57a7e3 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,8 @@ from kivy import app, properties -from kivy.uix.label import Label from kivy.uix.floatlayout import FloatLayout -from kivy.graphics import Color, Ellipse, Line, Rectangle -import kivy.utils - +from kivy.graphics import Color, Rectangle from hexmap import HexMapCell -from terrain import choose_random_terrain, Terrains class StrategyGame(FloatLayout): @@ -33,31 +29,6 @@ class StrategyGame(FloatLayout): hex_cell.disabled = False hex_cell.visible_on_map = True - # Determine the location of the solid hexagon cell. Needs to be offset from the centre of the hex. - radius = 2 * hex_cell.height - solid_x = hex_cell.x - hex_cell.height*2 - solid_y = hex_cell.y - hex_cell.height*2 - solid_size = (4*hex_cell.height, 4*hex_cell.height) - - with hex_cell.canvas.after: - # Pick a random terrain for each hex. - hex_cell.terrain = choose_random_terrain() - - # Create the solid background of the hexagon, from the bottom left coordinate of the hex. - hex_cell.terrain_colour = kivy.utils.get_color_from_hex(Terrains[hex_cell.terrain]['color']) - Color(*hex_cell.terrain_colour) - hex_cell.solid = Ellipse(pos=(solid_x, solid_y), size=solid_size, segments=6) - - # Create the outline of hexagon, based off the centre of the hex. - Color(*kivy.utils.get_color_from_hex('#000000')) - hex_cell.ell = Line(circle=(hex_cell.x, hex_cell.y, radius, 0, 360, 6), width=2) - - Color(0, 0, 0, 1) - hex_cell.coord_label = Label( - text=hex_cell.map_display_text(), - center_x=hex_cell.x, - center_y=hex_cell.y) - # Bind the cell code so as to update its position and size when the parent widget resizes. hex_cell.bind(pos=hex_cell.update_pos, size=hex_cell.update_pos) diff --git a/strategygame.kv b/strategygame.kv index d2b88ad..23cc1a7 100644 --- a/strategygame.kv +++ b/strategygame.kv @@ -33,5 +33,5 @@ background_color: .75, .71, .99, 1 : - size_hint: 1, None - height: self.width / math.sqrt(3) \ No newline at end of file +# size_hint: 1, 1 +# height: self.width / math.sqrt(3) \ No newline at end of file