changeset 420:da45406d08cd

Merge.
author Simon Cross <hodgestar@gmail.com>
date Sat, 07 Sep 2013 12:58:25 +0200
parents 3f15e071614f (current diff) 367bdb91b998 (diff)
children 2cb12311fedc
files
diffstat 4 files changed, 60 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
Binary file data/images/objects/gravity_well.png has changed
--- a/data/levels/level1	Sat Sep 07 12:55:38 2013 +0200
+++ b/data/levels/level1	Sat Sep 07 12:58:25 2013 +0200
@@ -62,6 +62,11 @@
   - door_switch
   classname: PuzzleDoor
   name: switch_door
+- args:
+  - [600, 600]
+  - 100
+  - 1000
+  classname: GravityWell
 lines:
 - - [750, 680]
   - [800, 680]
--- a/nagslang/game_object.py	Sat Sep 07 12:55:38 2013 +0200
+++ b/nagslang/game_object.py	Sat Sep 07 12:58:25 2013 +0200
@@ -211,6 +211,11 @@
     def collide_with_claw_attack(self, claw_attack):
         return True
 
+    def environmental_movement(self, dx, dy):
+        if (dx, dy) == (0, 0):
+            return
+        self.physicser.apply_impulse((dx, dy))
+
     @classmethod
     def requires(cls):
         """Hints for the level editor"""
@@ -593,3 +598,53 @@
 
     def apply_effect(self, protagonist):
         protagonist.force_wolf_form()
+
+
+class GravityWell(GameObject):
+    zorder = ZORDER_FLOOR
+    # How often to hit the player
+    rate = 5
+
+    def __init__(self, space, position, size, force):
+        body = make_body(10, pymunk.inf, position)
+        # Adjust shape relative to position
+        self.shape = pymunk.Circle(body, size)
+        self._ticks = 0
+        self.force = force
+        self.shape.collision_type = COLLISION_TYPE_SWITCH
+        self.shape.sensor = True
+        super(GravityWell, self).__init__(
+            SingleShapePhysicser(space, self.shape),
+            render.ImageRenderer(resources.get_image(
+                'objects', 'gravity_well.png')),
+        )
+
+    def collide_with_protagonist(self, protagonist):
+        # We're called every frame we're colliding, so
+        # There are timing issues with stepping on and
+        # off terrian, but as long as the rate is reasonably
+        # low, they shouldn't impact gameplay
+        if self._ticks == 0:
+            self.apply_effect(protagonist)
+        self._ticks += 1
+        if self._ticks > self.rate:
+            self._ticks = 0
+
+    def collide_with_furniture(self, furniture):
+        # We're called every frame we're colliding, so
+        # There are timing issues with stepping on and
+        # off terrian, but as long as the rate is reasonably
+        # low, they shouldn't impact gameplay
+        if self._ticks == 0:
+            self.apply_effect(furniture)
+        self._ticks += 1
+        if self._ticks > self.rate:
+            self._ticks = 0
+
+    def apply_effect(self, object_to_move):
+        object_to_move.environmental_movement(self.force, self.force)
+
+    @classmethod
+    def requires(cls):
+        return [("name", "string"), ("position", "coordinates"),
+                ("outline", "polygon (convex)")]
--- a/nagslang/protagonist.py	Sat Sep 07 12:55:38 2013 +0200
+++ b/nagslang/protagonist.py	Sat Sep 07 12:58:25 2013 +0200
@@ -326,11 +326,6 @@
     def add_item(self, item):
         self.world.inventory.add(item)
 
-    def environmental_movement(self, dx, dy):
-        if (dx, dy) == (0, 0):
-            return
-        self.physicser.apply_impulse((dx, dy))
-
     def get_health_level(self):
         """Return current health level
         """