comparison nagslang/game_object.py @ 416:bea0ea5b98df

Well, gravity.
author davidsharpe@lantea.local
date Sat, 07 Sep 2013 12:52:16 +0200
parents c08d409a1c87
children 01f48d8dc56a
comparison
equal deleted inserted replaced
415:9d2a8dfba670 416:bea0ea5b98df
209 return True 209 return True
210 210
211 def collide_with_claw_attack(self, claw_attack): 211 def collide_with_claw_attack(self, claw_attack):
212 return True 212 return True
213 213
214 def environmental_movement(self, dx, dy):
215 if (dx, dy) == (0, 0):
216 return
217 self.physicser.apply_impulse((dx, dy))
218
214 @classmethod 219 @classmethod
215 def requires(cls): 220 def requires(cls):
216 """Hints for the level editor""" 221 """Hints for the level editor"""
217 return [("name", "string")] 222 return [("name", "string")]
218 223
591 tile_alpha = 150 596 tile_alpha = 150
592 zorder = ZORDER_HIGH 597 zorder = ZORDER_HIGH
593 598
594 def apply_effect(self, protagonist): 599 def apply_effect(self, protagonist):
595 protagonist.force_wolf_form() 600 protagonist.force_wolf_form()
601
602 class GravityWell(GameObject):
603 zorder = ZORDER_FLOOR
604 # How often to hit the player
605 rate = 5
606
607 def __init__(self, space, position, size, force):
608 body = make_body(10, pymunk.inf, position)
609 # Adjust shape relative to position
610 self.shape = pymunk.Circle(body, size)
611 self._ticks = 0
612 self.force = force
613 self.shape.collision_type = COLLISION_TYPE_SWITCH
614 self.shape.sensor = True
615 super(GravityWell, self).__init__(
616 SingleShapePhysicser(space, self.shape),
617 render.ImageRenderer(resources.get_image(
618 'objects', 'gravity_well.png')),
619 )
620
621 def collide_with_protagonist(self, protagonist):
622 # We're called every frame we're colliding, so
623 # There are timing issues with stepping on and
624 # off terrian, but as long as the rate is reasonably
625 # low, they shouldn't impact gameplay
626 if self._ticks == 0:
627 self.apply_effect(protagonist)
628 self._ticks += 1
629 if self._ticks > self.rate:
630 self._ticks = 0
631
632 def collide_with_furniture(self, furniture):
633 # We're called every frame we're colliding, so
634 # There are timing issues with stepping on and
635 # off terrian, but as long as the rate is reasonably
636 # low, they shouldn't impact gameplay
637 if self._ticks == 0:
638 self.apply_effect(furniture)
639 self._ticks += 1
640 if self._ticks > self.rate:
641 self._ticks = 0
642
643 def apply_effect(self, object):
644 object.environmental_movement(self.force, self.force)
645
646 @classmethod
647 def requires(cls):
648 return [("name", "string"), ("position", "coordinates"),
649 ("outline", "polygon (convex)")]