From b074d2de01a972dd2b602d8d007d85332c61fe20 Mon Sep 17 00:00:00 2001 From: kleph Date: Sat, 12 Mar 2016 15:22:58 +0100 Subject: [PATCH] PEP-8 --- 02_dynamic_bsp_rooms.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/02_dynamic_bsp_rooms.py b/02_dynamic_bsp_rooms.py index a75fdb7..24eada6 100644 --- a/02_dynamic_bsp_rooms.py +++ b/02_dynamic_bsp_rooms.py @@ -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 = []