# HG changeset patch # User Neil Muller # Date 1378118706 -7200 # Node ID 93aa745d57ff67b32da2e560ccdfa4c1968d7246 # Parent 96bdfadeb461a623c850f309b639aa4c1069c6f1 draw protagnist bounding box in debug mode. Redo drawing logic to avoid pymunk noise diff -r 96bdfadeb461 -r 93aa745d57ff nagslang/protagonist.py --- a/nagslang/protagonist.py Mon Sep 02 12:01:25 2013 +0200 +++ b/nagslang/protagonist.py Mon Sep 02 12:45:06 2013 +0200 @@ -1,10 +1,13 @@ import pymunk import pymunk.pygame_util +import pygame + from nagslang.constants import COLLISION_TYPE_PLAYER from nagslang.game_object import ( GameObject, SingleShapePhysicser, FacingImageRenderer) from nagslang.mutators import FLIP_H +from nagslang.options import options from nagslang.resources import resources @@ -132,6 +135,19 @@ self._body.apply_impulse((dx, dy)) def render(self, surface): - # Uncomment to draw pymunk shape as well: - # pymunk.pygame_util.draw(surface, self._shapes[self.form]) + if options.debug: + # Less general that pymunk.pygame_utils.draw, but also a + # lot less noisy + color = pygame.color.THECOLORS['lightblue'] + if hasattr(self._shapes[self.form], 'get_vertices'): + # polygon bounding box + points = [pymunk.pygame_util.to_pygame(p, surface) + for p in self._shapes[self.form].get_vertices()] + pygame.draw.lines(surface, color, True, points, 2) + else: + # draw the circle + centre = pymunk.pygame_util.to_pygame( + self._shapes[self.form].body.position, surface) + radius = int(self._shapes[self.form].radius) + pygame.draw.circle(surface, color, centre, radius, 2) super(Protagonist, self).render(surface)