Mercurial > scrounge
changeset 55:d278a39dc4d6
animate opening chests
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sun, 28 Aug 2011 22:57:39 +0200 |
| parents | 83a5c8c1e1a6 |
| children | 2eeda60e4f04 |
| files | src/thing.py |
| diffstat | 1 files changed, 31 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/thing.py Sun Aug 28 22:42:21 2011 +0200 +++ b/src/thing.py Sun Aug 28 22:57:39 2011 +0200 @@ -17,6 +17,7 @@ depth = getattr(self.parent, 'depth', None) self.rect.midbottom = (self.parent.rect.midbottom[0], depth) + class DoorSprite(display.Sprite): def __init__(self, x, y, vertical): if vertical: @@ -40,6 +41,30 @@ self.rect.move_ip(0, -2) +class ChestSprite(display.Sprite): + def __init__(self, x, y): + super(ChestSprite, self).__init__(x, y, 'things.png', 1, 1) + self.animation = None + + def update(self): + if self.animation: + try: + self.animation.next() + except StopIteration: + self.animation = None + + def anim_open(self): + yield + yield + yield + yield + self.rect.move_ip(0, -2) + yield + self.image = self.frames[2][1] + yield + yield + self.rect.move_ip(0, 2) + class Thing(object): tx, ty = 0, 1 @@ -78,9 +103,14 @@ tx, ty = 1, 1 blocks = True + def __init__(self, x, y): + self.x = x + self.y = y + self.sprite = ChestSprite(x, y) + def hit(self, damage=0): - self.sprite.image = self.sprite.frames[2][self.ty] self.blocks = False + self.sprite.animation = self.sprite.anim_open() class Plant(Thing):
