# HG changeset patch # User Jeremy Thurgood # Date 1378390257 -7200 # Node ID 9d186b897d82c9f36f75386e1048824f44efb6d4 # Parent 9b56e954c674ce9d1797c3976905f807f1771920 Toggle switch, sans art. diff -r 9b56e954c674 -r 9d186b897d82 data/levels/level1 --- a/data/levels/level1 Thu Sep 05 15:58:24 2013 +0200 +++ b/data/levels/level1 Thu Sep 05 16:10:57 2013 +0200 @@ -13,8 +13,8 @@ classname: FloorSwitch name: light_switch - args: - - [300, 600] - classname: FloorSwitch + - [350, 250] + classname: ToggleSwitch name: door_switch - args: - [300, 500] diff -r 9b56e954c674 -r 9d186b897d82 nagslang/game_object.py --- a/nagslang/game_object.py Thu Sep 05 15:58:24 2013 +0200 +++ b/nagslang/game_object.py Thu Sep 05 16:10:57 2013 +0200 @@ -307,6 +307,30 @@ ("end2", "coordinates"), ("key_state", "puzzler")] +class ToggleSwitch(GameObject): + zorder = ZORDER_LOW + + def __init__(self, space, position): + body = make_body(None, None, position) + self.shape = pymunk.Circle(body, 20) + self.shape.sensor = True + self.toggle_on = False + super(ToggleSwitch, self).__init__( + SingleShapePhysicser(space, self.shape), + render.ShapeStateRenderer(), + puzzle.ParentAttrPuzzler('toggle_on'), + interactible=environment.Interactible( + environment.Action(self._toggle)), + ) + + def _toggle(self, protagonist): + self.toggle_on = not self.toggle_on + + @classmethod + def requires(cls): + return [("name", "string"), ("position", "coordinates")] + + class Bullet(GameObject): def __init__(self, space, position, impulse): body = make_body(1, pymunk.inf, position) diff -r 9b56e954c674 -r 9d186b897d82 nagslang/puzzle.py --- a/nagslang/puzzle.py Thu Sep 05 15:58:24 2013 +0200 +++ b/nagslang/puzzle.py Thu Sep 05 16:10:57 2013 +0200 @@ -77,6 +77,18 @@ return [("name", "string"), ("collision_types", "list of ints")] +class ParentAttrPuzzler(Puzzler): + def __init__(self, attr_name): + self._attr_name = attr_name + + def get_state(self): + return getattr(self.game_object, self._attr_name) + + @classmethod + def requires(cls): + return [("name", "string"), ("attr_name", "string")] + + class StateProxyPuzzler(Puzzler): def __init__(self, state_source): self._state_source = state_source