changeset 282:9d186b897d82

Toggle switch, sans art.
author Jeremy Thurgood <firxen@gmail.com>
date Thu, 05 Sep 2013 16:10:57 +0200
parents 9b56e954c674
children 1dd05d03ad21
files data/levels/level1 nagslang/game_object.py nagslang/puzzle.py
diffstat 3 files changed, 38 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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]
--- 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)
--- 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