Refactor move into move and push

This commit is contained in:
PAlexanderFranklin 2023-05-17 04:40:57 -07:00
parent cf2bf0ae51
commit d3a4523d3d
2 changed files with 15 additions and 17 deletions

View File

@ -9,15 +9,12 @@ class Block:
self.gameMap = gameMap self.gameMap = gameMap
self.sprite = pygame.Rect((x*tile) + 2, (y*tile) + 2, tile - 2, tile - 2) self.sprite = pygame.Rect((x*tile) + 2, (y*tile) + 2, tile - 2, tile - 2)
def move(self, x, y, caller=False): def pushed(self, x, y, caller, pusher):
try: if self.gameMap[self.x + x][self.y + y]:
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 + x][self.y + y].move(x, y, caller=self) self.gameMap[self.x][self.y] = 0
self.gameMap[self.x][self.y] = 0 self.x += x
self.x += x self.sprite.x = (self.x*tile)+2
self.sprite.x = (self.x*tile)+2 self.y += y
self.y += y self.sprite.y = (self.y*tile)+2
self.sprite.y = (self.y*tile)+2 self.gameMap[self.x][self.y] = self
self.gameMap[self.x][self.y] = self
except Exception as error:
raise error

View File

@ -33,15 +33,16 @@ class Player:
except: except:
pass pass
def move(self, x, y, caller=False): def move(self, x, y):
try: try:
if caller:
raise Exception("Cannot push other players.")
if self.gameMap[self.x + x][self.y + y]: 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.gameMap[self.x][self.y] = 0
self.x += x self.x += x
self.y += y self.y += y
self.gameMap[self.x][self.y] = self self.gameMap[self.x][self.y] = self
except Exception as error: except Exception as error:
raise error raise error
def pushed(self, x, y, caller, pusher):
raise Exception("Cannot push other players.")