Ignore:
Timestamp:
09/01/13 17:18:12 (8 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

Put werewolf facing direction magic back.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r62 r63  
     1import math
    12
    23
     
    89        raise NotImplementedError()
    910
    10     def render_position(self):
     11    def render_position(self, surface):
     12        raise NotImplementedError()
     13
     14    def render_angle(self):
    1115        raise NotImplementedError()
    1216
     
    2125    def render_position(self):
    2226        return (0, 0)
     27
     28    def render_angle(self):
     29        return 0
    2330
    2431
     
    3744        import pymunk.pygame_util
    3845        return pymunk.pygame_util.to_pygame(pos, surface)
    39         return (int(pos.x), int(pos.y))
     46
     47    def render_angle(self):
     48        return self._shape.body.angle
    4049
    4150
    4251class Renderer(object):
    43     def render(self, surface, pos):
     52    def render(self, surface, pos, angle):
    4453        raise NotImplementedError()
     54
     55
     56def image_pos(image, pos):
     57    return (pos[0] - image.get_width() / 2,
     58            pos[1] - image.get_height() / 2)
    4559
    4660
     
    4963        self._image = image
    5064
    51     def render(self, surface, pos):
    52         surface.blit(self._image, pos)
     65    def render(self, surface, pos, angle):
     66        surface.blit(self._image, image_pos(self._image, pos))
     67
     68
     69class FacingImageRenderer(Renderer):
     70    def __init__(self, left_image, right_image):
     71        self._images = {
     72            'left': left_image,
     73            'right': right_image,
     74        }
     75
     76    def get_image(self, angle):
     77        if abs(angle) < math.pi / 2:
     78            return self._images['right']
     79        return self._images['left']
     80
     81    def render(self, surface, pos, angle):
     82        image = self.get_image(angle)
     83        surface.blit(image, image_pos(image, pos))
    5384
    5485
     
    5788        self._shape = shape
    5889
    59     def render(self, surface, pos):
     90    def render(self, surface, pos, angle):
    6091        import pymunk.pygame_util
    6192        pymunk.pygame_util.draw(surface, self._shape)
     
    79110    def render(self, surface):
    80111        return self.renderer.render(
    81             surface, self.physicser.render_position(surface))
     112            surface, self.physicser.render_position(surface),
     113            self.physicser.render_angle())
Note: See TracChangeset for help on using the changeset viewer.