Mercurial > scrounge
changeset 24:81766ab43cce
opening doors
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Mon, 22 Aug 2011 19:01:59 +0200 |
| parents | 334585726885 |
| children | 3216ed15bcbc |
| files | thing.py |
| diffstat | 1 files changed, 30 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/thing.py Mon Aug 22 18:48:31 2011 +0200 +++ b/thing.py Mon Aug 22 19:01:59 2011 +0200 @@ -14,6 +14,29 @@ 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: + tx = 1 + else: + tx = 0 + super(DoorSprite, self).__init__(x, y, 'things.png', tx, 0) + self.animation = None + + def update(self): + if self.animation: + try: + self.animation.next() + except StopIteration: + self.animation = None + + def anim_open(self): + self.depth += 2 + for step in range(8): + yield + self.rect.move_ip(0, -2) + + class Thing(object): tx, ty = 0, 1 @@ -22,24 +45,25 @@ def __init__(self, x, y): self.x = x self.y = y + self.sprite = display.Sprite(self.x, self.y, 'things.png', + self.tx, self.ty) def render(self, to_display): - self.sprite = display.Sprite(self.x, self.y, 'things.png', - self.tx, self.ty) to_display.sprites.add(self.sprite) to_display.shadows.add(ShadowSprite(self.sprite)) class Door(Thing): - tx, ty = 0, 0 - def __init__(self, x, y, vertical): self.x = x self.y = y self.blocks = True self.vertical = vertical - if self.vertical: - self.tx = 1 + self.sprite = DoorSprite(self.x, self.y, self.vertical) + + def hit(self): + self.sprite.animation = self.sprite.anim_open() + self.blocks = False class Entrance(Thing):
