An example of item
This commit is contained in:
parent
343e107b86
commit
2ba7330ff5
|
@ -1,4 +1,4 @@
|
|||
from ..interfaces import Entity
|
||||
from ..interfaces import Entity, FightingEntity
|
||||
|
||||
class Item(Entity):
|
||||
held:bool
|
||||
|
@ -13,3 +13,21 @@ class Item(Entity):
|
|||
|
||||
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)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from ..interfaces import FightingEntity
|
||||
|
||||
class Monster(FightingEntity):
|
||||
def behaviour(self, map):
|
||||
def act(self, map):
|
||||
pass
|
||||
|
||||
class Squirrel(Monster):
|
||||
|
|
|
@ -72,6 +72,9 @@ class Entity:
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue