# HG changeset patch # User Neil Muller # Date 1378113604 -7200 # Node ID ecba9550ad8dd81d61201bdd33a6a9d70c05b225 # Parent 9ef5c5810dcdfedd17cd03e4618ad11ff1e94230 Fill the exterior with the blackness of space diff -r 9ef5c5810dcd -r ecba9550ad8d nagslang/level.py --- a/nagslang/level.py Mon Sep 02 11:20:17 2013 +0200 +++ b/nagslang/level.py Mon Sep 02 11:20:04 2013 +0200 @@ -24,6 +24,7 @@ self.basetile = 'tiles/floor.png' self._tile_image = None self._surface = None + self._exterior = False def load(self): @@ -62,7 +63,8 @@ if index: add_polygon(polygon, index, num_points) - def save(self): + def all_closed(self): + """Check if all the polygons are closed""" closed = True for poly in self.polygons.values(): if len(poly) == 0: @@ -74,6 +76,10 @@ elif poly[-1] != poly[0]: closed = False print "\033[31mError: polygon not closed\033[0m" + return closed + + def save(self): + closed = self.all_closed() if not closed: print 'Not saving the level' return @@ -113,10 +119,26 @@ def get_background(self): self._draw_background() + self._draw_exterior() # Draw polygons self._draw_walls() return self._surface + def _draw_exterior(self, force=False): + """Fill the exterior of the level with black""" + if self._exterior and not force: + return + surface = pygame.surface.Surface((self.x, self.y), pgl.SRCALPHA) + surface.fill(pygame.color.THECOLORS["black"]) + for index, polygon in self.polygons.items(): + if len(polygon) > 1: + pointlist = [self.point_to_pygame(p) for p in polygon] + # filled polygons + pygame.draw.polygon(surface, pygame.color.THECOLORS['white'], + pointlist, 0) + self._surface.blit(surface, (0, 0), special_flags=pgl.BLEND_RGBA_MULT) + self._exterior = True + def _draw_background(self, force=False): if self._tile_image is None: self._tile_image = resources.get_image(self.basetile)