Tweak level loading code
[erdslangetjie.git] / erdslangetjie / level.py
index 3214cf665fb7ec3f7e718015de74cbf887297f96..645a62f7678aca49f89f85a024dbaf4cc9ecd327 100644 (file)
@@ -14,8 +14,11 @@ class Level(object):
     def load(self, levelfile):
         """Load the level"""
         self.data = []
-        for line in levelfile.readlines():
-            self.data.append(list(line))
+        # Because of how kivy's coordinate system works,
+        # we reverse the lines so things match up between
+        # the file and the display (top of file == top of display)
+        for line in reversed(levelfile.readlines()):
+            self.data.append(list(line.strip('\n')))
 
     def load_tiles(self):
         """Load the list of tiles for the level"""
@@ -44,3 +47,16 @@ class Level(object):
 
     def at_exit(self, pos):
         return pos in self.exit_pos
+
+    def blocked(self, pos):
+        if pos[0] < 0:
+            return True
+        if pos[1] < 0:
+            return True
+        try:
+            tile = self.data[pos[1]][pos[0]]
+        except IndexError:
+            return True
+        if tile == '.':
+            return True
+        return False