diff nagslang/game_object.py @ 282:9d186b897d82

Toggle switch, sans art.
author Jeremy Thurgood <firxen@gmail.com>
date Thu, 05 Sep 2013 16:10:57 +0200
parents 9b56e954c674
children 248b8fdb160c
line wrap: on
line diff
--- 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)