This commit is contained in:
kleph 2016-03-12 15:22:58 +01:00
parent c64e376da4
commit b074d2de01

View file

@ -12,6 +12,7 @@ TILE_SIZE_Y = 16
MIN_LEAF_SIZE = 7
class Leaf:
""" Leaf of the BSP """
@ -79,6 +80,7 @@ class Leaf:
for x in range(0, self.width):
ground.blit((self.x + x)*TILE_SIZE_X, (self.y+y)*TILE_SIZE_Y)
class Room:
""" room """
@ -108,19 +110,20 @@ class Room:
for x in range(0, self.width):
wall.blit((self.x+x)*TILE_SIZE_X, (self.y + self.height-1)*TILE_SIZE_Y)
def generate_tree():
# init tree
tree = [Leaf(0, 0, 30, 30, 0)]
#tree = [Leaf(0, 0, 10, 10, 0)]
#tree = [Leaf(0, 0, 5, 5, 0)]
# tree = [Leaf(0, 0, 10, 10, 0)]
# tree = [Leaf(0, 0, 5, 5, 0)]
# split leaves until none succeed
split_done = True
while split_done:
split_done = False
for l in tree:
if l.left_leaf == None and l.right_leaf == None:
if (l.split()):
if l.left_leaf and l.right_leaf:
if l.split():
tree.append(l.left_leaf)
tree.append(l.right_leaf)
split_done = True
@ -138,9 +141,10 @@ def generate_tree():
# main window
window = pyglet.window.Window()
@window.event
def on_key_press(symbol, modifiers):
#TODO: ugly hack
# TODO: ugly hack
global level_tree
if symbol == key.Q:
@ -154,6 +158,7 @@ def on_key_press(symbol, modifiers):
elif symbol == key.ENTER:
print('Enter !')
@window.event
def on_draw():
window.clear()
@ -167,20 +172,20 @@ def draw_tree(t):
"""
for l in t:
# draw only last leaves
if l.left_leaf == None and l.right_leaf == None:
if l.left_leaf and l.right_leaf:
l.draw(tiles[TILE_ROAD])
for l in t:
# draw only last leaves
if l.left_leaf == None and l.right_leaf == None:
if l.left_leaf and l.right_leaf:
if l.room:
l.room.draw(tiles[TILE_WALL], tiles[TILE_GROUND])
# init random
#TODO add seed mode (how ?)
# TODO add seed mode (how ?)
random.seed()
label = pyglet.text.Label('Plop World', x = window.width*5/6, y = window.height*5/6, anchor_x='center', anchor_y='center')
label = pyglet.text.Label('Plop World', x=window.width*5/6, y=window.height*5/6, anchor_x='center', anchor_y='center')
# load images
tiles = []