changeset 302:a0a471ad2ee8

Pass bullet hits through to the target
author Stefano Rivera <stefano@rivera.za.net>
date Thu, 05 Sep 2013 23:57:50 +0200
parents 893f148a2f13
children 24bd56bd17bd
files nagslang/game_object.py
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/nagslang/game_object.py	Thu Sep 05 23:56:25 2013 +0200
+++ b/nagslang/game_object.py	Thu Sep 05 23:57:50 2013 +0200
@@ -148,6 +148,10 @@
     def animate(self):
         self.renderer.animate()
 
+    def hit(self, weapon):
+        '''Was hit with a weapon (such as a bullet)'''
+        pass
+
     def collide_with_protagonist(self, protagonist):
         """Called as a `pre_solve` collision callback with the protagonist.
 
@@ -357,11 +361,13 @@
         r = self.get_space().segment_query(self.last_position, position)
         self.last_position = position
         for collision in r:
-            if (collision.shape.collision_type == self.source_collision_type
-                    or collision.shape == self.physicser.get_shape()
-                    or collision.shape.sensor):
+            shape = collision.shape
+            if (shape.collision_type == self.source_collision_type
+                    or shape == self.physicser.get_shape()
+                    or shape.sensor):
                 continue
-            print "Hit", collision.shape.collision_type
+            if hasattr(shape, 'physicser'):
+                shape.physicser.game_object.hit(self)
             self.physicser.remove_from_space()
             self.remove = True
             break