Changeset 218:9e2ef2f15035


Ignore:
Timestamp:
Sep 4, 2013, 1:06:33 PM (7 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Message:

Better rendering and movement detection.

Location:
nagslang
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • nagslang/enemies.py

    r217 r218  
    3434
    3535class PatrollingAlien(Enemy):
     36    is_moving = True  # Always walking.
    3637
    3738    def __init__(self, space, position, end_position):
  • nagslang/game_object.py

    r217 r218  
    118118
    119119    zorder = ZORDER_LOW
     120    is_moving = False  # `True` if a movement animation should play.
    120121
    121122    def __init__(self, physicser, renderer, puzzler=None, overlay=None):
     
    150151        self.renderer.animate()
    151152
    152     def is_moving(self):
    153         """Returns `True` if this object is moving.
    154 
    155         This is mostly for movement-based animation renderers to look at.
    156         """
    157         return self.physicser.get_velocity().length > 0
    158 
    159153    def collide_with_protagonist(self):
    160154        """Called as a `pre_solve` collision callback with the protagonist.
  • 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):
  • nagslang/render.py

    r217 r218  
    100100class MovementAnimatedRenderer(TimedAnimatedRenderer):
    101101    def animate(self):
    102         if self.game_object.is_moving():
     102        if self.game_object.is_moving:
    103103            self.advance_tick()
    104104        else:
Note: See TracChangeset for help on using the changeset viewer.