Fix typo and attribute error
(it's better to declare all class attributes in constructor)
This commit is contained in:
parent
1befb38cb1
commit
5e06fdb3df
1 changed files with 8 additions and 9 deletions
17
03_map.py
17
03_map.py
|
@ -32,7 +32,7 @@ class Leaf:
|
||||||
|
|
||||||
def is_terminal(self):
|
def is_terminal(self):
|
||||||
""" Returns True if the leave has no children """
|
""" Returns True if the leave has no children """
|
||||||
if self.left_leave or self.right_leave:
|
if self.left_leaf or self.right_leaf:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -136,7 +136,6 @@ class Room:
|
||||||
tilemap[self.x + x][self.y + self.height - 1] = Level.TILE_WALL
|
tilemap[self.x + x][self.y + self.height - 1] = Level.TILE_WALL
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Level:
|
class Level:
|
||||||
TILE_WALL = 0
|
TILE_WALL = 0
|
||||||
TILE_ROAD = 1
|
TILE_ROAD = 1
|
||||||
|
@ -148,7 +147,7 @@ class Level:
|
||||||
self.tilemap = [[self.TILE_ROAD for y in range(0, sizey)] for x in range(0, sizex)]
|
self.tilemap = [[self.TILE_ROAD for y in range(0, sizey)] for x in range(0, sizex)]
|
||||||
if tile_file:
|
if tile_file:
|
||||||
self.load_tileset(tile_file)
|
self.load_tileset(tile_file)
|
||||||
self.generate_tree()
|
self.tree = self.generate_tree()
|
||||||
|
|
||||||
def load_tileset(self, tile_file):
|
def load_tileset(self, tile_file):
|
||||||
resource_file = open(tile_file)
|
resource_file = open(tile_file)
|
||||||
|
@ -162,17 +161,18 @@ class Level:
|
||||||
|
|
||||||
def generate_tree(self):
|
def generate_tree(self):
|
||||||
# init tree
|
# init tree
|
||||||
self.tree = [Leaf(0, 0, 30, 30, 0)]
|
tree = [Leaf(0, 0, 30, 30, 0)]
|
||||||
|
|
||||||
# split leaves until none succeed
|
# split leaves until none succeed
|
||||||
# Lists are ordered. Tree will be created and travel from left to right
|
# Lists are ordered. Tree will be created and travel from left to right
|
||||||
for l in self.tree:
|
for l in tree:
|
||||||
if l.split():
|
if l.split():
|
||||||
self.tree.append(l.left_leaf)
|
tree.append(l.left_leaf)
|
||||||
self.tree.append(l.right_leaf)
|
tree.append(l.right_leaf)
|
||||||
|
|
||||||
# create rooms from partitions
|
# create rooms from partitions
|
||||||
self.tree[0].generate_rooms(self.tilemap)
|
tree[0].generate_rooms(self.tilemap)
|
||||||
|
return tree
|
||||||
|
|
||||||
def draw_map(self):
|
def draw_map(self):
|
||||||
for y in range(0, self.sizey):
|
for y in range(0, self.sizey):
|
||||||
|
@ -230,7 +230,6 @@ def on_key_press(symbol, modifiers):
|
||||||
def on_draw():
|
def on_draw():
|
||||||
window.clear()
|
window.clear()
|
||||||
level.draw_tree()
|
level.draw_tree()
|
||||||
|
|
||||||
label.draw()
|
label.draw()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue