From: Neil Date: Mon, 15 Apr 2013 12:40:05 +0000 (+0200) Subject: can_move check for player objects X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=acb9e253be9b8d6858682832060c2b3bcf2c416b;p=erdslangetjie.git can_move check for player objects --- diff --git a/erdslangetjie/player.py b/erdslangetjie/player.py index 6fc26e8..2f8def2 100644 --- a/erdslangetjie/player.py +++ b/erdslangetjie/player.py @@ -12,6 +12,11 @@ class PlayerSprite(object): def move(self, direction): self.pos = (self.pos[0] + direction[0], self.pos[1] + direction[1]) + def can_move(self, direction, level): + '''Check if we can move in the given direction''' + cand_pos = (self.pos[0] + direction[0], self.pos[1] + direction[1]) + return not level.blocked(cand_pos) + def get_image(self): return self.sprite