From 26196a7dca3e5b40d0268a8674eba2f53d9213ca Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 10 Nov 2020 22:02:41 +0100 Subject: [PATCH] Move the camera with the player --- dungeonbattle/entities/player.py | 8 ++++++++ dungeonbattle/game.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dungeonbattle/entities/player.py b/dungeonbattle/entities/player.py index bef881c..2dce91e 100644 --- a/dungeonbattle/entities/player.py +++ b/dungeonbattle/entities/player.py @@ -13,6 +13,14 @@ class Player(FightingEntity): current_xp: int = 0 max_xp: int = 10 + def move(self, y: int, x: int) -> None: + """ + When the player moves, move the camera of the map. + """ + super().move(y, x) + self.map.currenty = y + self.map.currentx = x + def move_up(self) -> bool: return self.check_move(self.y - 1, self.x, True) diff --git a/dungeonbattle/game.py b/dungeonbattle/game.py index c393602..23cc598 100644 --- a/dungeonbattle/game.py +++ b/dungeonbattle/game.py @@ -50,8 +50,8 @@ class Game: self.map.currenty = 1 self.map.currentx = 6 self.player = Player() - self.player.move(1, 6) self.map.add_entity(self.player) + self.player.move(1, 6) self.map.spawn_random_entities(randint(1, 5)) @staticmethod