Add requirements and enable simple Python 2/3 compatibility.

This commit is contained in:
Dorian 2016-11-09 22:36:05 -05:00
parent db876192ec
commit d85027abdc
4 changed files with 33 additions and 34 deletions

View File

@ -3,10 +3,12 @@ from math import ceil
from kivy.logger import Logger from kivy.logger import Logger
from kivy.uix.label import Label from kivy.uix.label import Label
from kivy.graphics import Color, Line from kivy.graphics import Color, Line, Ellipse
import kivy.utils import kivy.utils
from kivy.vector import Vector from kivy.vector import Vector
from terrain import choose_random_terrain, Terrains
MapCoords = collections.namedtuple('MapCoords', ['row', 'col']) 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.cube_coords = self.even_r_to_cube(self.coords.row / 3, self.coords.col / 2)
self.selected = False self.selected = False
self.visible_on_map = 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_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 @staticmethod
def even_r_to_cube(row, col): def even_r_to_cube(row, col):

2
launch_app.sh Normal file
View File

@ -0,0 +1,2 @@
#!/bin/sh
python main.py --size=1280x700

31
main.py
View File

@ -1,12 +1,8 @@
from kivy import app, properties from kivy import app, properties
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout from kivy.uix.floatlayout import FloatLayout
from kivy.graphics import Color, Ellipse, Line, Rectangle from kivy.graphics import Color, Rectangle
import kivy.utils
from hexmap import HexMapCell from hexmap import HexMapCell
from terrain import choose_random_terrain, Terrains
class StrategyGame(FloatLayout): class StrategyGame(FloatLayout):
@ -33,31 +29,6 @@ class StrategyGame(FloatLayout):
hex_cell.disabled = False hex_cell.disabled = False
hex_cell.visible_on_map = True 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. # 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) hex_cell.bind(pos=hex_cell.update_pos, size=hex_cell.update_pos)

View File

@ -33,5 +33,5 @@
background_color: .75, .71, .99, 1 background_color: .75, .71, .99, 1
<HexMapCell>: <HexMapCell>:
size_hint: 1, None # size_hint: 1, 1
height: self.width / math.sqrt(3) # height: self.width / math.sqrt(3)