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)
45 def at_exit(self, pos):
46 return pos in self.exit_pos
48 def blocked(self, pos):
54 tile = self.data[pos[1]][pos[0]]
62 class LevelList(object):
68 level_list = load(self.LEVELS)
69 for line in level_list:
71 if os.path.exists(filepath(line)):
72 level_file = load(line)
73 self.levels.append(Level(level_file))
76 print 'Level list includes non-existant level %s' % line
80 def get_current_level(self):
81 if self._cur_level < len(self.levels):
82 return self.levels[self._cur_level]
86 def advance_to_next_level(self):
88 return self.get_current_level()