Mercurial > qq
changeset 17:31c17b907fad
Separate level rendering.
| author | sheep@ghostwheel |
|---|---|
| date | Sun, 05 Jul 2009 23:32:42 +0200 |
| parents | 4223254474e1 |
| children | 13da8f9bed5f |
| files | qq.py |
| diffstat | 1 files changed, 19 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/qq.py Sun Jul 05 23:19:43 2009 +0200 +++ b/qq.py Sun Jul 05 23:32:42 2009 +0200 @@ -39,6 +39,7 @@ self.cache[key] = tiles return tiles + class SortedUpdates(pygame.sprite.RenderUpdates): """A sprite group that sorts them by depth.""" @@ -151,13 +152,13 @@ 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) @@ -173,6 +174,20 @@ 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 = {} @@ -181,9 +196,6 @@ 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) @@ -257,7 +269,7 @@ 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)) @@ -346,6 +358,6 @@ 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()
