All entities can move, not only players

This commit is contained in:
Yohann D'ANELLO 2020-11-10 22:10:28 +01:00
parent 2045a57907
commit ec6b90fba2
2 changed files with 16 additions and 12 deletions

View File

@ -21,18 +21,6 @@ class Player(FightingEntity):
self.map.currenty = y
self.map.currentx = x
def move_up(self) -> bool:
return self.check_move(self.y - 1, self.x, True)
def move_down(self) -> bool:
return self.check_move(self.y + 1, self.x, True)
def move_left(self) -> bool:
return self.check_move(self.y, self.x - 1, True)
def move_right(self) -> bool:
return self.check_move(self.y, self.x + 1, True)
def level_up(self) -> None:
while self.current_xp > self.max_xp:
self.level += 1

View File

@ -135,6 +135,22 @@ class Entity:
self.y = y
self.x = x
def move_up(self, force: bool = False) -> bool:
return self.move(self.y - 1, self.x) if force else \
self.check_move(self.y - 1, self.x, True)
def move_down(self, force: bool = False) -> bool:
return self.move(self.y + 1, self.x) if force else \
self.check_move(self.y + 1, self.x, True)
def move_left(self, force: bool = False) -> bool:
return self.move(self.y, self.x - 1) if force else \
self.check_move(self.y, self.x - 1, True)
def move_right(self, force: bool = False) -> bool:
return self.move(self.y, self.x + 1) if force else \
self.check_move(self.y, self.x + 1, True)
def act(self, m: Map) -> None:
"""
Define the action of the entity that is ran each tick.