Start work on alternative hex grid layout.
This commit is contained in:
parent
30a8e27f4a
commit
f0fdbc18bd
10
debug.kv
10
debug.kv
|
@ -1,15 +1,7 @@
|
|||
#:import random random
|
||||
|
||||
<Widget>:
|
||||
canvas.after:
|
||||
Color:
|
||||
rgba: 1,1,1,.5
|
||||
Line:
|
||||
rectangle: self.x, self.y, self.width, self.height
|
||||
width: 2
|
||||
|
||||
<DebugLabel@Button>:
|
||||
size: self.parent.size
|
||||
pos: self.parent.pos
|
||||
background_color: random.random(), random.random(), random.random(), 0.6
|
||||
text: 'debuglabel'
|
||||
text: 'debuglabel'
|
||||
|
|
|
@ -13,8 +13,7 @@ a = Analysis(['main.py'],
|
|||
win_no_prefer_redirects=False,
|
||||
win_private_assemblies=False,
|
||||
cipher=block_cipher)
|
||||
pyz = PYZ(a.pure, a.zipped_data,
|
||||
cipher=block_cipher)
|
||||
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
|
||||
exe = EXE(pyz,
|
||||
a.scripts,
|
||||
a.binaries,
|
||||
|
|
74
main.py
74
main.py
|
@ -1,11 +1,20 @@
|
|||
import random
|
||||
|
||||
from kivy import app, properties
|
||||
from kivy.uix.floatlayout import FloatLayout
|
||||
from kivy.graphics import Color, Rectangle
|
||||
from kivy.uix.button import Button
|
||||
from kivy.uix.label import Label
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
from kivy.graphics import Color, Rectangle, Ellipse
|
||||
|
||||
from hexmap import HexMapCell
|
||||
|
||||
|
||||
class StrategyGame(FloatLayout):
|
||||
class HexSpace(Label):
|
||||
def __init__(self):
|
||||
super(HexSpace, self).__init__(size_hint=(0.5, 1), text=':)')
|
||||
|
||||
|
||||
class StrategyGame(BoxLayout):
|
||||
main_map = properties.ObjectProperty(None)
|
||||
status = properties.ObjectProperty(None)
|
||||
map_rows = properties.NumericProperty(0)
|
||||
|
@ -14,23 +23,54 @@ class StrategyGame(FloatLayout):
|
|||
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
|
||||
for row in range(0, self.map_rows):
|
||||
|
||||
# Add hex cells to make up the map.
|
||||
hex_cell = HexMapCell(row, col)
|
||||
hex_cell.disabled = True
|
||||
self.main_map.add_widget(hex_cell)
|
||||
hex_map_row = BoxLayout(orientation='horizontal')
|
||||
|
||||
# Add overlay conditionally.
|
||||
if (row % 6 == 1 and col % 2 == 1) or (row % 6 == 4 and col % 2 == 0) and (col > 0):
|
||||
hex_cell.disabled = False
|
||||
hex_cell.visible_on_map = True
|
||||
if row % 2 == 1:
|
||||
hex_map_row.add_widget(HexSpace())
|
||||
|
||||
# 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)
|
||||
for col in range(0, self.map_cols):
|
||||
# map_tile = HexMapCell(col=col, row=row)
|
||||
# map_tile.visible_on_map = True
|
||||
# map_tile.disabled = False
|
||||
|
||||
# map_tile.bind(pos=map_tile.update_pos, size=map_tile.update_pos)
|
||||
|
||||
map_tile = Button(text="{} {}".format(col, row), background_color=(
|
||||
random.random(), random.random(), random.random(), 0.6))
|
||||
with map_tile.canvas.after:
|
||||
Color(random.random(), random.random(), random.random(), 0.6)
|
||||
solid_x = map_tile.x - map_tile.height
|
||||
solid_y = map_tile.y - map_tile.height
|
||||
solid_size = (map_tile.height, map_tile.height)
|
||||
Ellipse(pos=(solid_x, solid_y), size=solid_size, segments=6)
|
||||
|
||||
hex_map_row.add_widget(map_tile)
|
||||
|
||||
if row % 2 == 0:
|
||||
hex_map_row.add_widget(HexSpace())
|
||||
|
||||
self.main_map.add_widget(hex_map_row)
|
||||
|
||||
# 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.
|
||||
# hex_cell = HexMapCell(row, col)
|
||||
# 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):
|
||||
# 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.
|
||||
# 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])
|
||||
|
|
|
@ -5,15 +5,15 @@
|
|||
id: _game
|
||||
main_map: _main_map
|
||||
status: _stats
|
||||
map_rows: 15
|
||||
map_rows: 10
|
||||
map_cols: 10
|
||||
BoxLayout:
|
||||
orientation: 'horizontal'
|
||||
GridLayout:
|
||||
BoxLayout:
|
||||
id: _main_map
|
||||
game: _game
|
||||
cols: root.map_cols
|
||||
size_hint: .75, 1
|
||||
orientation: 'vertical'
|
||||
BoxLayout:
|
||||
orientation: 'vertical'
|
||||
size_hint: .25, 1
|
||||
|
@ -31,7 +31,3 @@
|
|||
text: 'mini-map'
|
||||
size_hint: 1, .33
|
||||
background_color: .75, .71, .99, 1
|
||||
|
||||
<HexMapCell>:
|
||||
# size_hint: 1, 1
|
||||
# height: self.width / math.sqrt(3)
|
Loading…
Reference in New Issue