Friendly entities can now talk to the player, a sunflower entity was added to test this new feature. Related to issue #22
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env python
|
||||
from random import randint
|
||||
from enum import Enum, auto
|
||||
from math import sqrt
|
||||
from random import choice, randint
|
||||
from typing import List, Optional
|
||||
from typing import List, Optional, Any
|
||||
|
||||
from squirrelbattle.display.texturepack import TexturePack
|
||||
|
||||
@ -312,6 +313,12 @@ class Entity:
|
||||
from squirrelbattle.entities.items import Item
|
||||
return isinstance(self, Item)
|
||||
|
||||
def is_friendly(self) -> bool:
|
||||
"""
|
||||
Is this entity a friendly entity?
|
||||
"""
|
||||
return isinstance(self, FriendlyEntity)
|
||||
|
||||
@staticmethod
|
||||
def get_all_entity_classes():
|
||||
"""
|
||||
@ -320,7 +327,8 @@ class Entity:
|
||||
from squirrelbattle.entities.items import Heart, Bomb
|
||||
from squirrelbattle.entities.monsters import Beaver, Hedgehog, \
|
||||
Rabbit, TeddyBear
|
||||
return [Beaver, Bomb, Heart, Hedgehog, Rabbit, TeddyBear]
|
||||
from squirrelbattle.entities.friendly import Merchant,Sunflower
|
||||
return [Beaver, Bomb, Heart, Hedgehog, Rabbit, TeddyBear,Sunflower]
|
||||
|
||||
@staticmethod
|
||||
def get_all_entity_classes_in_a_dict() -> dict:
|
||||
@ -331,6 +339,7 @@ class Entity:
|
||||
from squirrelbattle.entities.monsters import Beaver, Hedgehog, Rabbit, \
|
||||
TeddyBear
|
||||
from squirrelbattle.entities.items import Bomb, Heart
|
||||
from squirrelbattle.entities.friendly import Merchant,Sunflower
|
||||
return {
|
||||
"Beaver": Beaver,
|
||||
"Bomb": Bomb,
|
||||
@ -339,6 +348,8 @@ class Entity:
|
||||
"Rabbit": Rabbit,
|
||||
"TeddyBear": TeddyBear,
|
||||
"Player": Player,
|
||||
"Merchant": Merchant,
|
||||
"Sunflower": Sunflower,
|
||||
}
|
||||
|
||||
def save_state(self) -> dict:
|
||||
@ -429,6 +440,7 @@ class FriendlyEntity(Entity):
|
||||
"""
|
||||
maxhealth: int
|
||||
health: int #Friendly entities can be killed
|
||||
dialogue_option : list
|
||||
|
||||
def __init__(self, maxhealth: int = 0, health: Optional[int] = None,
|
||||
*args, **kwargs) -> None:
|
||||
@ -436,6 +448,8 @@ class FriendlyEntity(Entity):
|
||||
self.maxhealth = maxhealth
|
||||
self.health = maxhealth if health is None else health
|
||||
|
||||
def talk_to(self, player : Player) -> None:
|
||||
#TODO
|
||||
def talk_to(self, player : Any) -> str:
|
||||
a = randint(0,len(self.dialogue_option)-1)
|
||||
return "The sunflower said : "+self.dialogue_option[a]
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user