# HG changeset patch # User Neil Muller # Date 1378129497 -7200 # Node ID c02a99502a9061368ae128352bd9777e0e5cb630 # Parent 9f3557e4833a840ef111e6fbae5a462fc273e665 Tweak 'draw exterior' logic to handle surrounded polygons better diff -r 9f3557e4833a -r c02a99502a90 nagslang/level.py --- a/nagslang/level.py Mon Sep 02 15:29:37 2013 +0200 +++ b/nagslang/level.py Mon Sep 02 15:44:57 2013 +0200 @@ -128,14 +128,28 @@ """Fill the exterior of the level with black""" if self._exterior and not force: return + white = pygame.color.THECOLORS['white'] + black = pygame.color.THECOLORS['black'] surface = pygame.surface.Surface((self.x, self.y), pgl.SRCALPHA) - surface.fill(pygame.color.THECOLORS["black"]) + surface.fill(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) + color = white + # If a polygon overlaps on of the existing polygons, + # it is treated as negative + # This is not a complete inversion, since any overlap + # triggers this (inversion is easy enough, but the + # behaviour doesn't seem useful) + # We also only check the vertexes - not breaking this + # assumption is left to the level designers + surface.lock() + for p in pointlist: + if surface.get_at(p) == white: + color = black + surface.unlock() + pygame.draw.polygon(surface, color, pointlist, 0) self._surface.blit(surface, (0, 0), special_flags=pgl.BLEND_RGBA_MULT) self._exterior = True