From 6c675fbac9add7052bac20e0312cc0d11628ce11 Mon Sep 17 00:00:00 2001 From: eichhornchen Date: Fri, 23 Oct 2020 15:15:37 +0200 Subject: [PATCH] added player actions for going up, down, left and right --- dungeonbattle/entities/player.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/dungeonbattle/entities/player.py b/dungeonbattle/entities/player.py index 66aed0c..98797bd 100644 --- a/dungeonbattle/entities/player.py +++ b/dungeonbattle/entities/player.py @@ -1,5 +1,27 @@ -from ..interfaces import FightingEntity +from .interfaces import FightingEntity class Player(FightingEntity): maxhealth = 20 - strength = 5 \ No newline at end of file + strength = 5 + + + def move_up(self, p : Player, m : Map) : + if p.y > 0 : + cell = Tile(Map.tiles[p.y-1][p.x]) + if can_walk(cell) : + p.y = p.y-1 + def move_down(self, p : Player, m : Map) : + if p.y < Map.height : + cell = Tile(Map.tiles[p.y+1][p.x]) + if can_walk(cell) : + p.y = p.y+1 + def move_left(self, p : Player, m : Map) : + if p.x > 0 : + cell = Tile(Map.tiles[p.y][p.x-1]) + if can_walk(cell) : + p.x = p.x-1 + def move_right(self, p : Player, m : Map) : + if p.x < Map.width : + cell = Tile(Map.tiles[p.y][p.x+1]) + if can_walk(cell) : + p.x = p.x+1