Mercurial > mhrok
changeset 47:abb35c96b871
Added dust clouds
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sat, 10 Mar 2012 18:10:11 +0100 |
| parents | e52060a30e29 |
| children | f0697a2de62a |
| files | mhrok/display.py mhrok/level.py mhrok/mhrok.png mhrok/mobs.py mhrok/sprites.py |
| diffstat | 5 files changed, 42 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mhrok/display.py Sat Mar 10 16:29:36 2012 +0100 +++ b/mhrok/display.py Sat Mar 10 18:10:11 2012 +0100 @@ -6,10 +6,13 @@ import cStringIO as StringIO except ImportError: import StringIO +import random import pygame from pygame import locals as pg +from mhrok import sprites + class SortedUpdates(pygame.sprite.RenderUpdates): """Sprite group with a depth for controlling drawing order.""" @@ -80,6 +83,13 @@ event = events.pop() getattr(self, 'on_%s' % event[0])(*event[1:]) + def on_mob_dust(self, mob, amount=4, delay=0): + for i in xrange(amount): + x = mob.sprite.rect.centerx + random.randint(-8, 8) + y = mob.sprite.rect.centery + random.randint(-2, 2) + self.sprites.add(sprites.Dust( + self.tiles, (x, y), delay + random.randint(0, 4))) + def on_room_light(self, room): self.light_room(room)
--- a/mhrok/level.py Sat Mar 10 16:29:36 2012 +0100 +++ b/mhrok/level.py Sat Mar 10 18:10:11 2012 +0100 @@ -63,11 +63,14 @@ def open(self, mob): self.mobs.remove(mob) self.events.append(('mob_open', mob)) + self.events.append(('mob_dust', mob, 20, 4)) - def stand(self, mob, direction): + def stand(self, mob, direction, dust=False): if direction is None: return self.events.append(('mob_stand', mob, direction)) + if dust: + self.events.append(('mob_dust', mob, 4)) def wait(self, mob, direction): self.events.append(('mob_wait', mob, direction)) @@ -75,6 +78,7 @@ def attack(self, mob, direction, other): other.hit(self, mob) self.events.append(('mob_attack', mob, direction, other)) + self.events.append(('mob_dust', mob, 4)) def is_blocked(self, pos): for m in self.mobs:
--- a/mhrok/mobs.py Sat Mar 10 16:29:36 2012 +0100 +++ b/mhrok/mobs.py Sat Mar 10 18:10:11 2012 +0100 @@ -127,7 +127,7 @@ except level.BlockedMob as e: level.attack(self, self.direction, e.mob) except level.BlockedWall: - level.stand(self, self.direction) + level.stand(self, self.direction, dust=True) return False else: level.stand(self, self.direction)
--- a/mhrok/sprites.py Sat Mar 10 16:29:36 2012 +0100 +++ b/mhrok/sprites.py Sat Mar 10 18:10:11 2012 +0100 @@ -177,4 +177,30 @@ self.set_radius(min(self.current_radius + 4, self.radius)) self.rect.center = self.owner.rect.center +class Dust(pygame.sprite.Sprite): + def __init__(self, frames, (x, y), delay=0): + super(Dust, self).__init__() + self.animation = self.dust_animation(frames, delay) + self.image = frames[40].copy() + self.image.set_alpha(0) + self.rect = self.image.get_rect() + self.rect.center = (x, y) + self.depth = y + for step, frame in enumerate([40, 41, 42, 43]): + frames[frame].set_alpha(192 - 32 * step) + + def dust_animation(self, frames, delay): + for step in xrange(delay): + yield None + for frame in [40, 41, 42, 43]: + self.image = frames[frame] + yield None + yield None + yield None + + def update(self): + try: + self.animation.next() + except StopIteration: + self.kill()
