Mercurial > nagslang
changeset 351:50fce787ae17
Hostile terrian objects
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Fri, 06 Sep 2013 16:13:43 +0200 |
parents | 4a665dc554b4 |
children | bf43cc2d8d0a |
files | nagslang/game_object.py |
diffstat | 1 files changed, 43 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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'