Mercurial > fhrl
changeset 14:7a3935873931
opening door
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Wed, 13 Mar 2013 23:36:51 +0100 |
| parents | 768d7bd98d15 |
| children | 55ee23d91598 |
| files | fhrl/level.py fhrl/mobs.py fhrl/stuff.png |
| diffstat | 3 files changed, 41 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/fhrl/level.py Wed Mar 13 22:30:50 2013 +0100 +++ b/fhrl/level.py Wed Mar 13 23:36:51 2013 +0100 @@ -95,6 +95,11 @@ if (x, y) == (self.hero.x, self.hero.y): return self.hero + def find_stuff(self, (x, y)): + for s in self.stuff: + if (x, y) == (s.x, s.y): + return s + def is_wall(self, (x, y)): if x < 0 or x > self.width: return True @@ -107,11 +112,9 @@ def is_blocked(self, (x, y)): if self.is_wall((x, y)): return True - for s in self.stuff: - if (x, y) == (s.x, s.y): - if s.kind in (5, 7): - return False - return True + s = self.find_stuff((x, y)) + if s and s.kind not in (5, 7, 8): + return True return False def __iter__(self):
--- a/fhrl/mobs.py Wed Mar 13 22:30:50 2013 +0100 +++ b/fhrl/mobs.py Wed Mar 13 23:36:51 2013 +0100 @@ -16,9 +16,25 @@ class ActBlocked(ActException): """Raised when you try to move into the wall.""" -class ActBump(ActException): + def __init__(self, pos=None): + self.pos = pos + + +class ActBumpMob(ActException): """Raised when you try to walk into a monster.""" + def __init__(self, pos=None, mob=None): + self.pos = pos + self.mob = mob + + +class ActBumpStuff(ActException): + """Raised when you try to walk into furniture.""" + + def __init__(self, pos=None, stuff=None): + self.pos = pos + self.stuff = stuff + class Sprite(pygame.sprite.DirtySprite): def __init__(self): @@ -48,6 +64,11 @@ self.kind = kind self.depth = -12 + def _morph_anim(self, display): + self.image = display.resources.stuff[self.kind] + return + yield + class Mob(Sprite): def __init__(self, kind, (x, y)): @@ -65,10 +86,13 @@ x = self.x + DX[d] y = self.y + DY[d] if level.is_blocked((x, y)): - raise ActBlocked() + s = level.find_stuff((x, y)) + if s: + raise ActBumpStuff((x, y), s) + raise ActBlocked((x, y)) m = level.find_mob((x, y)) if m: - raise ActBump() + raise ActBumpMob((x, y), m) self.x, self.y = x, y return self._walk_anim(d) @@ -104,6 +128,12 @@ if direction is not None: try: return [self.walk(direction, level)] + except ActBumpStuff as e: + if e.stuff.kind in (4, 6): + e.stuff.kind += 1 + else: + e.stuff.kind = 8 + return [e.stuff._morph_anim(display)] except ActException: pass return []
