Merge branch 'entities' into 'master'
Basic entities See merge request ynerant/dungeon-battle!4
This commit is contained in:
commit
514a3fcb64
|
@ -0,0 +1,33 @@
|
|||
from ..interfaces import Entity, FightingEntity
|
||||
|
||||
class Item(Entity):
|
||||
held:bool
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(self, *args, **kwargs)
|
||||
self.held = False
|
||||
|
||||
def drop(self, x:int, y:int):
|
||||
self.held = False
|
||||
self.move(x, y)
|
||||
|
||||
def hold(self):
|
||||
self.held = True
|
||||
|
||||
class Bomb(Item):
|
||||
damage:int = 5
|
||||
exploding:bool
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(self, *args, **kwargs)
|
||||
self.exploding = False
|
||||
|
||||
def drop(self, x:int, y:int):
|
||||
super.drop(self, x, y)
|
||||
self.exploding = True
|
||||
|
||||
def act(self, map):
|
||||
if self.exploding:
|
||||
for e in map.entities:
|
||||
if abs (e.x - self.x) + abs (e.y - self.y) <= 1 and isinstance(e,FightingEntity):
|
||||
e.take_damage(self, self.damage)
|
|
@ -0,0 +1,9 @@
|
|||
from ..interfaces import FightingEntity
|
||||
|
||||
class Monster(FightingEntity):
|
||||
def act(self, map):
|
||||
pass
|
||||
|
||||
class Squirrel(Monster):
|
||||
maxhealth = 10
|
||||
strength = 3
|
|
@ -0,0 +1,5 @@
|
|||
from ..interfaces import FightingEntity
|
||||
|
||||
class Player(FightingEntity):
|
||||
maxhealth = 20
|
||||
strength = 5
|
|
@ -37,8 +37,10 @@ class Map:
|
|||
width = len(lines[0])
|
||||
tiles = [[Tile(c)
|
||||
for x, c in enumerate(line)] for y, line in enumerate(lines)]
|
||||
|
||||
return Map(width, height, tiles, [])
|
||||
|
||||
|
||||
def draw_string(self) -> str:
|
||||
"""
|
||||
Draw the current map as a string object that can be rendered
|
||||
|
@ -64,15 +66,31 @@ class Tile(Enum):
|
|||
|
||||
|
||||
class Entity:
|
||||
y: int
|
||||
x: int
|
||||
img: str
|
||||
|
||||
def __init__(self, y: int, x: int, img: str):
|
||||
self.y = y
|
||||
self.x = x
|
||||
self.img = img
|
||||
y: int
|
||||
|
||||
def move(self, x: int, y: int) -> None:
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def act(self, m:Map):
|
||||
pass
|
||||
|
||||
class FightingEntity(Entity):
|
||||
maxhealth: int
|
||||
health: int
|
||||
strength: int
|
||||
|
||||
def __init__(self):
|
||||
self.health = self.maxhealth
|
||||
|
||||
def hit(self, opponent) -> None:
|
||||
opponent.take_damage(self, self.strength)
|
||||
|
||||
def take_damage(self, attacker, amount:int) -> None:
|
||||
self.health -= amount
|
||||
if self.health <= 0:
|
||||
self.die()
|
||||
|
||||
def die(self) -> None:
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue