can_move check for player objects
authorNeil <neil@dip.sun.ac.za>
Mon, 15 Apr 2013 12:40:05 +0000 (14:40 +0200)
committerNeil <neil@dip.sun.ac.za>
Mon, 15 Apr 2013 12:40:05 +0000 (14:40 +0200)
erdslangetjie/player.py

index 6fc26e887dcd2a4e057293e3dbe204b49024acd3..2f8def2976ae4bf0c7e1dabb6d295c2702108996 100644 (file)
@@ -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