Changeset 282:9d186b897d82 for nagslang


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

Toggle switch, sans art.

Location:
nagslang
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/game_object.py

    r281 r282  
    308308
    309309
     310class ToggleSwitch(GameObject):
     311    zorder = ZORDER_LOW
     312
     313    def __init__(self, space, position):
     314        body = make_body(None, None, position)
     315        self.shape = pymunk.Circle(body, 20)
     316        self.shape.sensor = True
     317        self.toggle_on = False
     318        super(ToggleSwitch, self).__init__(
     319            SingleShapePhysicser(space, self.shape),
     320            render.ShapeStateRenderer(),
     321            puzzle.ParentAttrPuzzler('toggle_on'),
     322            interactible=environment.Interactible(
     323                environment.Action(self._toggle)),
     324        )
     325
     326    def _toggle(self, protagonist):
     327        self.toggle_on = not self.toggle_on
     328
     329    @classmethod
     330    def requires(cls):
     331        return [("name", "string"), ("position", "coordinates")]
     332
     333
    310334class Bullet(GameObject):
    311335    def __init__(self, space, position, impulse):
  • nagslang/puzzle.py

    r235 r282  
    7878
    7979
     80class ParentAttrPuzzler(Puzzler):
     81    def __init__(self, attr_name):
     82        self._attr_name = attr_name
     83
     84    def get_state(self):
     85        return getattr(self.game_object, self._attr_name)
     86
     87    @classmethod
     88    def requires(cls):
     89        return [("name", "string"), ("attr_name", "string")]
     90
     91
    8092class StateProxyPuzzler(Puzzler):
    8193    def __init__(self, state_source):
Note: See TracChangeset for help on using the changeset viewer.