From d3a4523d3d5019a2803f32a5f4e8bb6393fd8293 Mon Sep 17 00:00:00 2001 From: PAlexanderFranklin Date: Wed, 17 May 2023 04:40:57 -0700 Subject: [PATCH] Refactor move into move and push --- blocks.py | 21 +++++++++------------ player.py | 11 ++++++----- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/blocks.py b/blocks.py index c1c2bbe..9f9e740 100644 --- a/blocks.py +++ b/blocks.py @@ -9,15 +9,12 @@ class Block: self.gameMap = gameMap self.sprite = pygame.Rect((x*tile) + 2, (y*tile) + 2, tile - 2, tile - 2) - def move(self, x, y, caller=False): - try: - if self.gameMap[self.x + x][self.y + y]: - self.gameMap[self.x + x][self.y + y].move(x, y, caller=self) - self.gameMap[self.x][self.y] = 0 - self.x += x - self.sprite.x = (self.x*tile)+2 - self.y += y - self.sprite.y = (self.y*tile)+2 - self.gameMap[self.x][self.y] = self - except Exception as error: - raise error \ No newline at end of file + def pushed(self, x, y, caller, pusher): + if self.gameMap[self.x + x][self.y + y]: + self.gameMap[self.x + x][self.y + y].pushed(x, y, self, pusher) + self.gameMap[self.x][self.y] = 0 + self.x += x + self.sprite.x = (self.x*tile)+2 + self.y += y + self.sprite.y = (self.y*tile)+2 + self.gameMap[self.x][self.y] = self \ No newline at end of file diff --git a/player.py b/player.py index e1818ed..5b4dc28 100644 --- a/player.py +++ b/player.py @@ -33,15 +33,16 @@ class Player: except: pass - def move(self, x, y, caller=False): + def move(self, x, y): try: - if caller: - raise Exception("Cannot push other players.") if self.gameMap[self.x + x][self.y + y]: - self.gameMap[self.x + x][self.y + y].move(x, y, caller=self) + self.gameMap[self.x + x][self.y + y].pushed(x, y, self, self) self.gameMap[self.x][self.y] = 0 self.x += x self.y += y self.gameMap[self.x][self.y] = self except Exception as error: - raise error \ No newline at end of file + raise error + + def pushed(self, x, y, caller, pusher): + raise Exception("Cannot push other players.") \ No newline at end of file