Merge remote-tracking branch 'origin/master' into display

# Conflicts:
#	dungeonbattle/entities/player.py
#	dungeonbattle/game.py
#	dungeonbattle/interfaces.py
#	dungeonbattle/mapdisplay.py
#	dungeonbattle/settings.py
#	dungeonbattle/tests/settings_test.py
#	dungeonbattle/texturepack.py
This commit is contained in:
Yohann D'ANELLO
2020-11-06 20:04:24 +01:00
17 changed files with 495 additions and 107 deletions

View File

@ -13,13 +13,20 @@ class Map:
height: int
tiles: list
currentx : int #coordinates of the point that should be on the topleft corner of the screen
currenty : int
currenty : int
def __init__(self, width: int, height: int, tiles: list, entities = []):
def __init__(self, width: int, height: int, tiles: list):
self.width = width
self.height = height
self.tiles = tiles
self.entities = entities
self.entities = []
def add_entity(self, entity: "Entity") -> None:
"""
Register a new entity in the map.
"""
self.entities.append(entity)
entity.map = self
@staticmethod
def load(filename: str):
@ -42,8 +49,7 @@ class Map:
tiles = [[Tile(c)
for x, c in enumerate(line)] for y, line in enumerate(lines)]
return Map(width, height, tiles, [])
return Map(width, height, tiles)
def draw_string(self, pack: TexturePack) -> str:
"""
@ -73,21 +79,39 @@ class Tile(Enum):
class Entity:
x: int
y: int
x: int
name : str
map: Map
def move(self, x: int, y: int) -> None:
self.x = x
def __init__(self):
self.y = 0
self.x = 0
def check_move(self, y: int, x: int, move_if_possible: bool = False)\
-> bool:
tile = self.map.tiles[y][x]
if tile.can_walk() and move_if_possible:
self.move(y, x)
return tile.can_walk()
def move(self, y: int, x: int) -> None:
self.y = y
def act(self, m:Map):
self.x = x
def act(self, m: Map) -> None:
"""
Define the action of the entity that is ran each tick.
By default, does nothing.
"""
pass
class FightingEntity(Entity):
maxhealth: int
health: int
strength: int
dead: bool
intelligence: int
charisma: int
dexterity: int
@ -95,15 +119,17 @@ class FightingEntity(Entity):
level: int
def __init__(self):
super().__init__()
self.health = self.maxhealth
self.dead = False
def hit(self, opponent) -> None:
def hit(self, opponent: "FightingEntity") -> None:
opponent.take_damage(self, self.strength)
def take_damage(self, attacker, amount:int) -> None:
def take_damage(self, attacker: "Entity", amount: int) -> None:
self.health -= amount
if self.health <= 0:
self.die()
def die(self) -> None:
pass
self.dead = True