From ec6b90fba2d13f3f916d6ad80d694dfd794e44b7 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 10 Nov 2020 22:10:28 +0100 Subject: [PATCH] All entities can move, not only players --- dungeonbattle/entities/player.py | 12 ------------ dungeonbattle/interfaces.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/dungeonbattle/entities/player.py b/dungeonbattle/entities/player.py index 2dce91e..c9a6334 100644 --- a/dungeonbattle/entities/player.py +++ b/dungeonbattle/entities/player.py @@ -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 diff --git a/dungeonbattle/interfaces.py b/dungeonbattle/interfaces.py index 82e9af2..4c281e4 100644 --- a/dungeonbattle/interfaces.py +++ b/dungeonbattle/interfaces.py @@ -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.