Ignore:
Timestamp:
09/04/13 13:06:33 (8 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

Better rendering and movement detection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/protagonist.py

    r217 r218  
    2727
    2828
     29class ProtagonistFormSelectionRenderer(render.RendererSelectionRenderer):
     30    def select_renderer(self):
     31        return self.game_object.render_form
     32
     33
    2934class Protagonist(GameObject):
    3035    """Representation of our fearless protagonist.
     
    4045    def __init__(self, space, position):
    4146        physicser = self._make_physics(space, position)
    42         self._setup_renderers()
     47        renderer = self._make_renderer()
    4348        self.inventory = {}
    4449        self.form = self.HUMAN_FORM
    4550        self.render_form = self.HUMAN_FORM
    46 
    47         super(Protagonist, self).__init__(
    48             physicser, self._renderers[self.form])
     51        self.angle = 0
     52        self.is_moving = False
     53
     54        super(Protagonist, self).__init__(physicser, renderer)
    4955        self.zorder = ZORDER_MID
    5056
     
    7985        return resources.get_image('creatures', name, transforms=transforms)
    8086
    81     def _setup_renderers(self):
    82         self.angle = 0
    83         self._renderers = {
     87    def _make_renderer(self):
     88        return ProtagonistFormSelectionRenderer({
    8489            self.HUMAN_FORM: render.FacingSelectionRenderer(
    8590                {
     
    118123                         self._get_image('werewolf_back_2.png', FLIP_H)], 3),
    119124                }),
    120         }
    121         for renderer in self._renderers.values():
    122             renderer.set_game_object(self)
     125        })
    123126
    124127    @classmethod
     
    144147        else:
    145148            self.render_form = self.WOLF_FORM
    146         self.renderer = self._renderers[self.render_form]
    147149
    148150    def go_human(self):
     
    157159        else:
    158160            self.render_form = self.HUMAN_FORM
    159         self.renderer = self._renderers[self.render_form]
    160161
    161162    def _switch_to_back(self):
     
    164165        elif self.render_form == self.WOLF_FORM:
    165166            self.render_form = self.WOLF_FORM_BACK
    166         self.renderer = self._renderers[self.render_form]
    167167
    168168    def _switch_to_front(self):
     
    171171        elif self.render_form == self.WOLF_FORM_BACK:
    172172            self.render_form = self.WOLF_FORM
    173         self.renderer = self._renderers[self.render_form]
    174173
    175174    def set_direction(self, dx, dy):
    176175        if (dx, dy) == (0, 0):
     176            self.is_moving = False
    177177            return
     178        self.is_moving = True
    178179        old_angle = self.angle
    179180        self.angle = pymunk.Vec2d((dx, dy)).angle
     
    201202        self.render_form = old_protagonist.render_form
    202203        self.inventory = old_protagonist.inventory
    203         self.renderer = self._renderers[self.render_form]
    204204
    205205    def toggle_form(self):
Note: See TracChangeset for help on using the changeset viewer.