Added a familiar class that follows the player around and hits monsters when it sees one. Added a trumpet, an instance of familiar. Closes #46.

This commit is contained in:
eichhornchen
2020-12-18 17:29:59 +01:00
parent 8ecbf13eae
commit dadafc84eb
5 changed files with 100 additions and 17 deletions

View File

@ -63,7 +63,10 @@ class Map:
"""
Registers a new entity in the map.
"""
self.entities.append(entity)
if entity.is_familiar() :
self.entities.insert(1,entity)
else :
self.entities.append(entity)
entity.map = self
def remove_entity(self, entity: "Entity") -> None:
@ -152,12 +155,15 @@ class Map:
entity.move(y, x)
self.add_entity(entity)
def tick(self) -> None:
def tick(self, p: Any) -> None:
"""
Triggers all entity events.
"""
for entity in self.entities:
entity.act(self)
if entity.is_familiar():
entity.act(p, self)
else :
entity.act(self)
def save_state(self) -> dict:
"""
@ -296,7 +302,7 @@ class Entity:
return self.move(self.y, self.x + 1) if force else \
self.check_move(self.y, self.x + 1, True)
def recalculate_paths(self, max_distance: int = 8) -> None:
def recalculate_paths(self, max_distance: int = 12) -> None:
"""
Uses Dijkstra algorithm to calculate best paths for other entities to
go to this entity. If self.paths is None, does nothing.
@ -386,6 +392,13 @@ class Entity:
"""
return isinstance(self, FriendlyEntity)
def is_familiar(self) -> bool:
"""
Is this entity a familiar?
"""
from squirrelbattle.entities.friendly import Familiar
return isinstance(self, Familiar)
def is_merchant(self) -> bool:
"""
Is this entity a merchant?
@ -408,9 +421,10 @@ class Entity:
from squirrelbattle.entities.items import BodySnatchPotion, Bomb, Heart
from squirrelbattle.entities.monsters import Tiger, Hedgehog, \
Rabbit, TeddyBear
from squirrelbattle.entities.friendly import Merchant, Sunflower
from squirrelbattle.entities.friendly import Merchant, Sunflower, \
Trumpet
return [BodySnatchPotion, Bomb, Heart, Hedgehog, Rabbit, TeddyBear,
Sunflower, Tiger, Merchant]
Sunflower, Tiger, Merchant, Trumpet]
@staticmethod
def get_all_entity_classes_in_a_dict() -> dict: