Changeset 95:ecba9550ad8d


Ignore:
Timestamp:
Sep 2, 2013, 9:20:04 AM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
rebase_source:
47caccec504010a8e8be52f2d1d96acc5a675497
Message:

Fill the exterior with the blackness of space

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/level.py

    r75 r95  
    2525        self._tile_image = None
    2626        self._surface = None
     27        self._exterior = False
    2728
    2829    def load(self):
     
    6364            add_polygon(polygon, index, num_points)
    6465
    65     def save(self):
     66    def all_closed(self):
     67        """Check if all the polygons are closed"""
    6668        closed = True
    6769        for poly in self.polygons.values():
     
    7577                closed = False
    7678                print "\033[31mError: polygon not closed\033[0m"
     79        return closed
     80
     81    def save(self):
     82        closed = self.all_closed()
    7783        if not closed:
    7884            print 'Not saving the level'
     
    114120    def get_background(self):
    115121        self._draw_background()
     122        self._draw_exterior()
    116123        # Draw polygons
    117124        self._draw_walls()
    118125        return self._surface
     126
     127    def _draw_exterior(self, force=False):
     128        """Fill the exterior of the level with black"""
     129        if self._exterior and not force:
     130            return
     131        surface = pygame.surface.Surface((self.x, self.y), pgl.SRCALPHA)
     132        surface.fill(pygame.color.THECOLORS["black"])
     133        for index, polygon in self.polygons.items():
     134            if len(polygon) > 1:
     135                pointlist = [self.point_to_pygame(p) for p in polygon]
     136                # filled polygons
     137                pygame.draw.polygon(surface, pygame.color.THECOLORS['white'],
     138                        pointlist, 0)
     139        self._surface.blit(surface, (0, 0), special_flags=pgl.BLEND_RGBA_MULT)
     140        self._exterior = True
    119141
    120142    def _draw_background(self, force=False):
Note: See TracChangeset for help on using the changeset viewer.