Anonymous avatar Anonymous committed 31c17b9

Separate level rendering.

Comments (0)

Files changed (1)

         self.cache[key] = tiles
         return tiles
 
+
 class SortedUpdates(pygame.sprite.RenderUpdates):
     """A sprite group that sorts them by depth."""
 
 
 
 class Level:
-    """ Load and store the map of the level, together with all the items."""
+    """Load and store the map of the level, together with all the items."""
 
     def __init__(self, filename="level.map"):
         self.load_file(filename)
 
     def load_file(self, filename="level.map"):
-        """ Load the level from specified file."""
+        """Load the level from specified file."""
 
         parser = ConfigParser.ConfigParser()
         parser.read(filename)
                            tile_width, tile_height)
         self.width = len(self.map[0])
         self.height = len(self.map)
+        y = 0
+        for line in self.map:
+            x = 0
+            for c in line:
+                if not self.is_wall(x, y):
+                    # floor
+                    if 'sprite' in self.key[c]:
+                        self.items[(x, y)] = self.key[c]
+                x += 1
+            y += 1
+
+    def render(self):
+        """Draw the level on the surface."""
+
         self.image = pygame.Surface((self.width*tile_width,
                                      self.height*tile_height))
         self.overlays = {}
             x = 0
             for c in line:
                 if not self.is_wall(x, y):
-                    # floor
-                    if 'sprite' in self.key[c]:
-                        self.items[(x, y)] = self.key[c]
                     try:
                         tile_x, tile_y = self.key[c]['tile'].split(',')
                         tile_x = int(tile_x)
         return self.get_bool(x, y, 'block')
 
     def draw(self, surface):
-        """ Draw the map on the provided surface."""
+        """Draw the map on the provided surface."""
 
         surface.blit(self.image, (0, 0))
 
 if __name__ == "__main__":
     pygame.init()
     pygame.display.set_mode((424, 320))
-    font = pygame.font.Font("MgOpenModataBold.ttf", 11)
+    # font = pygame.font.Font("MgOpenModataBold.ttf", 11)
     tiles = TileCache()
     Game().main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.