Changeset 126:c3af35561494


Ignore:
Timestamp:
Sep 2, 2013, 3:09:47 PM (7 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Message:

Cleaner switch/light rendering.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r123 r126  
    175175
    176176
    177 class ShapeRenderer(Renderer):
    178     def render(self, surface):
     177class ShapeStateRenderer(Renderer):
     178    """Renders the shape in a different colour depending on the state.
     179
     180    Requires the game object it's attached to to have a puzzler.
     181    """
     182    def render(self, surface):
     183        if self.game_object.puzzler.get_state():
     184            color = pygame.color.THECOLORS['green']
     185        else:
     186            color = pygame.color.THECOLORS['red']
     187
     188        self.game_object.get_shape().color = color
    179189        self._render_shape(surface)
    180         super(ShapeRenderer, self).render(surface)
     190        super(ShapeStateRenderer, self).render(surface)
    181191
    182192
     
    223233        super(FloorSwitch, self).__init__(
    224234            SingleShapePhysicser(space, self.shape),
    225             ShapeRenderer(),
     235            ShapeStateRenderer(),
    226236            FloorSwitchPuzzler(),
    227237        )
    228 
    229     def render(self, surface):
    230         if self.puzzler.get_state():
    231             self.shape.color = pygame.color.THECOLORS['green']
    232         else:
    233             self.shape.color = pygame.color.THECOLORS['red']
    234         super(FloorSwitch, self).render(surface)
    235238
    236239
     
    244247        super(FloorLight, self).__init__(
    245248            SingleShapePhysicser(space, self.shape),
    246             ShapeRenderer(),
     249            ShapeStateRenderer(),
    247250            StateProxyPuzzler(state_source),
    248251        )
    249 
    250     def render(self, surface):
    251         if self.puzzler.get_state():
    252             self.shape.color = pygame.color.THECOLORS['green']
    253         else:
    254             self.shape.color = pygame.color.THECOLORS['red']
    255         super(FloorLight, self).render(surface)
Note: See TracChangeset for help on using the changeset viewer.