Mercurial > nagslang
changeset 416:bea0ea5b98df
Well, gravity.
author | davidsharpe@lantea.local |
---|---|
date | Sat, 07 Sep 2013 12:52:16 +0200 |
parents | 9d2a8dfba670 |
children | 01f48d8dc56a |
files | data/images/objects/gravity_well.png data/levels/level1 nagslang/game_object.py nagslang/protagonist.py |
diffstat | 4 files changed, 59 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/data/levels/level1 Sat Sep 07 12:50:21 2013 +0200 +++ b/data/levels/level1 Sat Sep 07 12:52:16 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:50:21 2013 +0200 +++ b/nagslang/game_object.py Sat Sep 07 12:52:16 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,52 @@ 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): + object.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:50:21 2013 +0200 +++ b/nagslang/protagonist.py Sat Sep 07 12:52:16 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 """