Mercurial > skaapsteker
changeset 400:1501d9b7f5dd
Don't allow patrolling monsters to walk off edges
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sat, 09 Apr 2011 16:50:54 +0200 |
parents | 488ab520408c |
children | 55e00f186c6f |
files | skaapsteker/sprites/base.py |
diffstat | 1 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/skaapsteker/sprites/base.py Sat Apr 09 16:41:38 2011 +0200 +++ b/skaapsteker/sprites/base.py Sat Apr 09 16:50:54 2011 +0200 @@ -238,6 +238,22 @@ self.facing = 'left' self._update_image(True) + def check_floors(self, floors): + """If we're only on 1 floor tile, and our centre is beyond half way, + turn back""" + if len(floors) > 1: + return + + floor = floors[0] + + if self.facing == 'left': + if self.collide_rect.centerx < floor.collide_rect.centerx: + self.facing = 'right' + self._update_image(True) + else: + if self.collide_rect.centerx > floor.collide_rect.centerx: + self.facing = 'left' + self._update_image(True) class NPC(AnimatedGameSprite):