Changeset 441:f3ccb00df6a4


Ignore:
Timestamp:
04/09/11 17:41:20 (12 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Phase:
public
Message:

Add life stealing.

Location:
skaapsteker/sprites
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/sprites/base.py

    r434 r441  
    181181        else:
    182182            pos = pygame.Rect(self.rect.midright, (0, 0))
    183         projectile = cls(pos, direction=self.facing, hits=Player)
     183        projectile = cls(pos, direction=self.facing, hits=Player, source=self)
    184184        AddSpriteEvent.post(projectile)
    185185
     
    294294    VELOCITY = (10, 10) # pixels/s
    295295
    296     def setup(self, direction, hits, **opts):
     296    def setup(self, direction, hits, source, **opts):
    297297        super(Projectile, self).setup(**opts)
    298298        self.facing = direction
     299        self.source = source # source of the projectile (may be None)
    299300        self._update_image(True)  # ensure we get the direction right
    300301
     
    323324        if hasattr(other, 'damage'):
    324325            other.damage(self.DAMAGE)
     326        if hasattr(self.source, 'steal_life'):
     327            self.source.steal_life(self.DAMAGE)
    325328        self.explode()
    326329
  • skaapsteker/sprites/player.py

    r440 r441  
    242242            PlayerDied.post()
    243243
     244    def steal_life(self, damage_done):
     245        if 'steal' in self._me.tails:
     246            self._me.cur_health += damage_done * len(self._me.tails) / 32
     247            self._me.cur_health = min(self._me.cur_health, self._me.max_health)
     248
    244249    def restore(self):
    245250        """Restore player to max health (for restarting levels, etc.)"""
     
    355360        else:
    356361            pos = pygame.Rect(self.rect.midright, (0, 0))
    357         projectile = cls(pos, direction=self.facing, hits=Monster)
     362        projectile = cls(pos, direction=self.facing, hits=Monster, source=self)
    358363        AddSpriteEvent.post(projectile)
    359364
Note: See TracChangeset for help on using the changeset viewer.