Mercurial > blow
changeset 10:4df5c37a5da1
Boss
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sun, 28 Apr 2013 16:09:51 +0200 |
| parents | bca8f061086e |
| children | 9964f1c0236c |
| files | blow/boss.png blow/game_scene.py blow/resources.py blow/tree.png |
| diffstat | 4 files changed, 46 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/blow/game_scene.py Sun Apr 28 14:48:54 2013 +0200 +++ b/blow/game_scene.py Sun Apr 28 16:09:51 2013 +0200 @@ -121,11 +121,15 @@ self.chomp_animation, ])(scene) + def is_visible(self): + return self.rect.right > 0 and self.rect.left < 748 + def stun_animation(self, scene): self.image = self.frames[1] self.bounce = True self.stunned = True - scene.resources.hit.play() + if self.is_visible(): + scene.resources.hit.play() for i in xrange(30): yield self.image = self.frames[0] @@ -172,7 +176,8 @@ yield def chomp_animation(self, scene): - scene.resources.bark.play() + if self.is_visible(): + scene.resources.bark.play() self.image = self.frames[2] yield yield @@ -183,6 +188,42 @@ yield +class BossSprite(MonsterSprite): + def update(self, tick, scene): + super(MonsterSprite, self).update(tick, scene) + if self.stunned and self.on_ground(): + scene.resources.hit.play() + if self.animation is None and self.can_jump(): + self.animation = random.choice([ + self.walk_left_animation, + self.walk_right_animation, + self.stand_animation, + self.chomp_animation, + self.chomp_animation, + ])(scene) + + def chomp_animation(self, scene): + self.image = self.frames[2] + self.dy = -16 + self.dx = 0 + while self.dy < -4 or not self.on_ground(): + yield + if self.is_visible(): + scene.resources.hit.play() + yield + yield + yield + yield + self.image = self.frames[0] + + def stun(self, scene): + if self.stunned: + return + self.animation = self.stun_animation(scene) + self.dx = 6 + self.dy = -6 + + class SwordSprite(Sprite): def __init__(self, owner, *args, **kwargs): @@ -271,6 +312,8 @@ BOTTOM - random.randint(64, 256), ) self.monsters.add(monster) + boss = BossSprite(self.resources.boss) + self.monsters.add(boss) self.sprites.add(self.monsters) self.tree = TreeSprite(self.resources.tree)
--- a/blow/resources.py Sun Apr 28 14:48:54 2013 +0200 +++ b/blow/resources.py Sun Apr 28 16:09:51 2013 +0200 @@ -13,6 +13,7 @@ self.hero = self.load_atlas('hero.png', 64, 64) self.skeleton = self.load_atlas('skeleton.png', 64, 64) self.beast = self.load_atlas('beast.png', 64, 64) + self.boss = self.load_atlas('boss.png', 256, 256) self.weapons = self.load_atlas('weapons.png', 64, 64) self.effects = self.load_atlas('effects.png', 64, 64) self.tree = self.load_atlas('tree.png', 256, 256)
