Mercurial > nagslang
changeset 101:93aa745d57ff
draw protagnist bounding box in debug mode. Redo drawing logic to avoid pymunk noise
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Mon, 02 Sep 2013 12:45:06 +0200 |
parents | 96bdfadeb461 |
children | fd9c4db5ddfe |
files | nagslang/protagonist.py |
diffstat | 1 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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)