comparison nagslang/game_object.py @ 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 b00ed05f7364
children ce11e1cae0ed
comparison
equal deleted inserted replaced
301:893f148a2f13 302:a0a471ad2ee8
146 return self.renderer.render(surface) 146 return self.renderer.render(surface)
147 147
148 def animate(self): 148 def animate(self):
149 self.renderer.animate() 149 self.renderer.animate()
150 150
151 def hit(self, weapon):
152 '''Was hit with a weapon (such as a bullet)'''
153 pass
154
151 def collide_with_protagonist(self, protagonist): 155 def collide_with_protagonist(self, protagonist):
152 """Called as a `pre_solve` collision callback with the protagonist. 156 """Called as a `pre_solve` collision callback with the protagonist.
153 157
154 You can return `False` to ignore the collision, anything else 158 You can return `False` to ignore the collision, anything else
155 (including `None`) to process the collision as normal. 159 (including `None`) to process the collision as normal.
355 super(Bullet, self).animate() 359 super(Bullet, self).animate()
356 position = (self.physicser.position.x, self.physicser.position.y) 360 position = (self.physicser.position.x, self.physicser.position.y)
357 r = self.get_space().segment_query(self.last_position, position) 361 r = self.get_space().segment_query(self.last_position, position)
358 self.last_position = position 362 self.last_position = position
359 for collision in r: 363 for collision in r:
360 if (collision.shape.collision_type == self.source_collision_type 364 shape = collision.shape
361 or collision.shape == self.physicser.get_shape() 365 if (shape.collision_type == self.source_collision_type
362 or collision.shape.sensor): 366 or shape == self.physicser.get_shape()
367 or shape.sensor):
363 continue 368 continue
364 print "Hit", collision.shape.collision_type 369 if hasattr(shape, 'physicser'):
370 shape.physicser.game_object.hit(self)
365 self.physicser.remove_from_space() 371 self.physicser.remove_from_space()
366 self.remove = True 372 self.remove = True
367 break 373 break
368 374
369 375