comparison nagslang/game_object.py @ 351:50fce787ae17

Hostile terrian objects
author Neil Muller <drnlmuller@gmail.com>
date Fri, 06 Sep 2013 16:13:43 +0200
parents 282113d86d75
children 55752fc7b753
comparison
equal deleted inserted replaced
350:4a665dc554b4 351:50fce787ae17
478 def update(self, dt): 478 def update(self, dt):
479 super(ClawAttack, self).update(dt) 479 super(ClawAttack, self).update(dt)
480 if self.lifetime > 0.1: 480 if self.lifetime > 0.1:
481 self.physicser.remove_from_space() 481 self.physicser.remove_from_space()
482 self.remove = True 482 self.remove = True
483
484
485 class HostileTerrain(GameObject):
486 zorder = ZORDER_FLOOR
487 damage = None
488 tile = None
489 # How often to hit the player
490 rate = 5
491
492 def __init__(self, space, position, outline):
493 body = make_body(10, pymunk.inf, position)
494 # Adjust shape relative to position
495 shape_outline = [(p[0] - position[0], p[1] - position[1]) for
496 p in outline]
497 self.shape = pymunk.Poly(body, shape_outline)
498 self._ticks = 0
499 self.shape.collision_type = COLLISION_TYPE_SWITCH
500 self.shape.sensor = True
501 super(HostileTerrain, self).__init__(
502 SingleShapePhysicser(space, self.shape),
503 render.TiledRenderer(outline,
504 resources.get_image('tiles', self.tile)))
505
506 def collide_with_protagonist(self, protagonist):
507 # We're called every frame we're colliding, so
508 # There are timing issues with stepping on and
509 # off terrian, but as long as the rate is reasonably
510 # low, they shouldn't impact gameplay
511 if self._ticks == 0:
512 protagonist.lose_health(self.damage)
513 self._ticks += 1
514 if self._ticks > self.rate:
515 self._ticks = 0
516
517 @classmethod
518 def requires(cls):
519 return [("name", "string"), ("position", "coordinates"),
520 ("outline", "polygon")]
521
522
523 class AcidFloor(HostileTerrain):
524 damage = 1
525 tile = 'acid.png'