4 from data import load_image, load, filepath
9 def __init__(self, levelfile):
14 # Because of how kivy's coordinate system works,
15 # we reverse the lines so things match up between
16 # the file and the display (top of file == top of display)
17 for line in reversed(levelfile.readlines()):
18 self.data.append(list(line.strip('\n')))
21 """Load the list of tiles for the level"""
25 for j, line in enumerate(self.data):
27 for i, c in enumerate(line):
29 tile_line.append(load_image('tiles/floor.bmp'))
31 tile_line.append(load_image('tiles/wall.bmp'))
32 elif c == 'E' or c == 'X':
35 raise RuntimeError('Multiple entry points')
36 self.enter_pos = (i, j)
38 self.exit_pos.append((i, j))
39 tile_line.append(load_image('tiles/door.bmp'))
40 self.tiles.append(tile_line)
46 return len(self.tiles[0]), len(self.tiles)
48 def at_exit(self, pos):
49 return pos in self.exit_pos
51 def blocked(self, pos):
57 tile = self.data[pos[1]][pos[0]]
65 class LevelList(object):
71 level_list = load(self.LEVELS)
72 for line in level_list:
74 if os.path.exists(filepath(line)):
75 level_file = load(line)
76 self.levels.append(Level(level_file))
79 print 'Level list includes non-existant level %s' % line
83 def get_current_level(self):
84 if self._cur_level < len(self.levels):
85 return self.levels[self._cur_level]
89 def advance_to_next_level(self):
91 return self.get_current_level()