squirrel-battle/dungeonbattle/entities/items.py

38 lines
916 B
Python
Raw Normal View History

2020-11-06 14:33:26 +00:00
from ..interfaces import Entity, FightingEntity, Map
2020-10-23 14:51:48 +00:00
class Item(Entity):
2020-11-06 14:33:26 +00:00
held: bool
2020-10-23 14:51:48 +00:00
def __init__(self, *args, **kwargs):
2020-11-06 14:33:26 +00:00
super().__init__(*args, **kwargs)
2020-10-23 14:51:48 +00:00
self.held = False
2020-11-06 14:33:26 +00:00
2020-11-06 15:13:28 +00:00
def drop(self, y: int, x: int) -> None:
2020-10-23 14:51:48 +00:00
self.held = False
2020-11-06 15:13:28 +00:00
self.move(y, x)
2020-11-06 14:33:26 +00:00
def hold(self) -> None:
2020-10-23 14:51:48 +00:00
self.held = True
2020-10-23 16:02:57 +00:00
2020-11-06 14:33:26 +00:00
2020-10-23 16:02:57 +00:00
class Bomb(Item):
2020-11-10 20:47:36 +00:00
name = "bomb"
2020-11-06 14:33:26 +00:00
damage: int = 5
exploding: bool
2020-10-23 16:02:57 +00:00
def __init__(self, *args, **kwargs):
2020-11-06 14:33:26 +00:00
super().__init__(*args, **kwargs)
2020-10-23 16:02:57 +00:00
self.exploding = False
2020-11-06 14:33:26 +00:00
def drop(self, x: int, y: int) -> None:
super().drop(x, y)
2020-10-23 16:02:57 +00:00
self.exploding = True
2020-11-06 14:33:26 +00:00
def act(self, m: Map) -> None:
2020-10-23 16:02:57 +00:00
if self.exploding:
2020-11-06 14:33:26 +00:00
for e in m.entities:
if abs(e.x - self.x) + abs(e.y - self.y) <= 1 and \
isinstance(e, FightingEntity):
2020-10-23 16:02:57 +00:00
e.take_damage(self, self.damage)