Interact with items

This commit is contained in:
Yohann D'ANELLO
2020-11-11 16:47:19 +01:00
parent 2b5d82db57
commit f11fb31c28
3 changed files with 35 additions and 9 deletions

View File

@ -1,8 +1,12 @@
from typing import Optional
from .player import Player
from ..interfaces import Entity, FightingEntity, Map
class Item(Entity):
held: bool
hold_by: Optional["Player"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@ -10,18 +14,30 @@ class Item(Entity):
def drop(self, y: int, x: int) -> None:
self.held = False
self.hold_by = None
self.map.add_entity(self)
self.move(y, x)
def hold(self) -> None:
def hold(self, player: "Player") -> None:
self.held = True
self.hold_by = player
self.map.remove_entity(self)
class Heart(Item):
name = "heart"
name: str = "heart"
healing: int = 5
def hold(self, player: "Player") -> None:
"""
When holding a heart, heal the player and don't put item in inventory.
"""
player.health = min(player.maxhealth, player.health + self.healing)
return super().hold(player)
class Bomb(Item):
name = "bomb"
name: str = "bomb"
damage: int = 5
exploding: bool