# HG changeset patch # User Neil Muller # Date 1378476823 -7200 # Node ID 50fce787ae176512c015435984f8293be704d76d # Parent 4a665dc554b4cfffc81a107380b57c27d16bee9a Hostile terrian objects diff -r 4a665dc554b4 -r 50fce787ae17 nagslang/game_object.py --- a/nagslang/game_object.py Fri Sep 06 15:54:43 2013 +0200 +++ b/nagslang/game_object.py Fri Sep 06 16:13:43 2013 +0200 @@ -480,3 +480,46 @@ if self.lifetime > 0.1: self.physicser.remove_from_space() self.remove = True + + +class HostileTerrain(GameObject): + zorder = ZORDER_FLOOR + damage = None + tile = None + # How often to hit the player + rate = 5 + + def __init__(self, space, position, outline): + body = make_body(10, pymunk.inf, position) + # Adjust shape relative to position + shape_outline = [(p[0] - position[0], p[1] - position[1]) for + p in outline] + self.shape = pymunk.Poly(body, shape_outline) + self._ticks = 0 + self.shape.collision_type = COLLISION_TYPE_SWITCH + self.shape.sensor = True + super(HostileTerrain, self).__init__( + SingleShapePhysicser(space, self.shape), + render.TiledRenderer(outline, + resources.get_image('tiles', self.tile))) + + 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: + protagonist.lose_health(self.damage) + self._ticks += 1 + if self._ticks > self.rate: + self._ticks = 0 + + @classmethod + def requires(cls): + return [("name", "string"), ("position", "coordinates"), + ("outline", "polygon")] + + +class AcidFloor(HostileTerrain): + damage = 1 + tile = 'acid.png'