# HG changeset patch # User Simon Cross # Date 1378551505 -7200 # Node ID da45406d08cda5764213f16b3d080833cbe70ec8 # Parent 3f15e071614f36bba8bcd37ae54cb2fc267c90db# Parent 367bdb91b998acd485cd37e75e337b455779d63d Merge. diff -r 3f15e071614f -r da45406d08cd data/images/objects/gravity_well.png Binary file data/images/objects/gravity_well.png has changed diff -r 3f15e071614f -r da45406d08cd data/levels/level1 --- 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] diff -r 3f15e071614f -r da45406d08cd nagslang/game_object.py --- 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)")] diff -r 3f15e071614f -r da45406d08cd nagslang/protagonist.py --- 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 """