From: Simon Cross Date: Sat, 17 May 2014 22:53:57 +0000 (+0200) Subject: Ability to move player with location. X-Git-Tag: 0.1~10^2~7 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=0dcb7a00f2ad80c4b544e3e04dce4b008dac1ad7;p=naja.git Ability to move player with location. --- diff --git a/naja/actions.py b/naja/actions.py index 869c692..e1ec1e0 100644 --- a/naja/actions.py +++ b/naja/actions.py @@ -296,6 +296,12 @@ class ShiftLocations(LocationAction): board.shift_locations( self.data['direction'], self.data.get('skip_current', True)) + if self.data.get('move_player', False): + pos = { + 'NORTH': (0, -1), 'SOUTH': (0, 1), + 'EAST': (1, 0), 'WEST': (-1, 0), + }.get(self.data['direction'], (0, 0)) + board.player.force_position(pos, delta=True) class RotateLocations(LocationAction): diff --git a/naja/player.py b/naja/player.py index 58cb824..d47e826 100644 --- a/naja/player.py +++ b/naja/player.py @@ -151,6 +151,13 @@ class Player(object): return True return False + def force_position(self, pos, delta=True): + if delta: + pos = (self.position[0] + pos[0], + self.position[1] + pos[1]) + if (0 <= pos[0] < 5 and 0 <= pos[1] < 5): + self.position = pos + def set_gameboard(self, gameboard): self.gameboard = gameboard