squirrel-battle/dungeonbattle/entities/items.py
2020-11-06 16:13:28 +01:00

37 lines
898 B
Python

from ..interfaces import Entity, FightingEntity, Map
class Item(Entity):
held: bool
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.held = False
def drop(self, y: int, x: int) -> None:
self.held = False
self.move(y, x)
def hold(self) -> None:
self.held = True
class Bomb(Item):
damage: int = 5
exploding: bool
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.exploding = False
def drop(self, x: int, y: int) -> None:
super().drop(x, y)
self.exploding = True
def act(self, m: Map) -> None:
if self.exploding:
for e in m.entities:
if abs(e.x - self.x) + abs(e.y - self.y) <= 1 and \
isinstance(e, FightingEntity):
e.take_damage(self, self.damage)