Changeset 118:c02a99502a90


Ignore:
Timestamp:
Sep 2, 2013, 1:44:57 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

Tweak 'draw exterior' logic to handle surrounded polygons better

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/level.py

    r98 r118  
    129129        if self._exterior and not force:
    130130            return
     131        white = pygame.color.THECOLORS['white']
     132        black = pygame.color.THECOLORS['black']
    131133        surface = pygame.surface.Surface((self.x, self.y), pgl.SRCALPHA)
    132         surface.fill(pygame.color.THECOLORS["black"])
     134        surface.fill(black)
    133135        for index, polygon in self.polygons.items():
    134136            if len(polygon) > 1:
    135137                pointlist = [self.point_to_pygame(p) for p in polygon]
    136138                # filled polygons
    137                 pygame.draw.polygon(surface, pygame.color.THECOLORS['white'],
    138                                     pointlist, 0)
     139                color = white
     140                # If a polygon overlaps on of the existing polygons,
     141                # it is treated as negative
     142                # This is not a complete inversion, since any overlap
     143                # triggers this (inversion is easy enough, but the
     144                # behaviour doesn't seem useful)
     145                # We also only check the vertexes - not breaking this
     146                # assumption is left to the level designers
     147                surface.lock()
     148                for p in pointlist:
     149                    if surface.get_at(p) == white:
     150                        color = black
     151                surface.unlock()
     152                pygame.draw.polygon(surface, color, pointlist, 0)
    139153        self._surface.blit(surface, (0, 0), special_flags=pgl.BLEND_RGBA_MULT)
    140154        self._exterior = True
Note: See TracChangeset for help on using the changeset viewer.