entity module¶
Defines the entity ‘abstract’ class? And a few of the initial implementations of the class
- class entity.Actor(*, x: int = 0, y: int = 0, char: str = '?', color: Tuple[int, int, int] = (255, 255, 255), name: str = '<Unanamed>', ai_cls: Type[BaseAI], equipment: Equipment, fighter: Fighter, inventory: Inventory, level: Level)¶
Bases:
entity.EntityClass used to represent actors within our world Check entity_factories for some implementation examples Things like enemies, players are actors It’s a subclass of entity so you can use the entity component system (need to validate this, python oop things are not clear as Java)
- property is_alive: bool¶
Checks if actor is alive
- Returns
True if actor is alive, False otherwise
- Return type
bool
- parent: Union[GameMap, Inventory]¶
- class entity.Entity(parent: Optional[GameMap] = None, x: int = 0, y: int = 0, char: str = '?', color: Tuple[int, int, int] = (255, 255, 255), name: str = '<Unnamed>', blocks_movement: bool = False, render_order: RenderOrder = RenderOrder.CORPSE)¶
Bases:
objectThis is a thing that exists in our gameworld Using the Entity Component System model, an entity should be data Behavior should not be part of the entity itself, but rather be a component that is part of the entity defined by
BaseComponent- Parameters
parent (GameMap, Optional) – Whose gamemap this entity is on
x (int) – x coordinate of the entity
y (int) – y coordinate of the entity
char – Character to represent the entity
color (Tuple[int, int, int]) – Color of the entity
name (str) – Name of the entity
blocks_movement (bool) – If entity blocks movement
render_order (RenderOrder) – What order to render the entity
- distance(x: int, y: int) float¶
Calculates distance between self and x,y coordinate using Pythagorean Theorem
- Parameters
x (int) – x coordinate of the entity
y (int) – y coordinate of the entity
- Returns
distance between self and x,y coordinate
- Return type
float
- property gamemap: GameMap¶
Returns the parent’s gamemap
- Returns
GameMap that this entity existis in
- Return type
GameMap
- move(dx: int, dy: int) None¶
Move the entity by the given amount
- Parameters
dx (int) – Delta x to move by
dy (int) – Delta y to move by
- parent: Union[GameMap, Inventory]¶
- place(x: int, y: int, gamemap: Optional[GameMap] = None) None¶
Use this when you wish to move a entity across GameMaps It will remove itself from its parents gamemap and add it to the new gamemap
- Parameters
x (int) – x coordinate of the entity
y (int) – y coordinate of the entity
gamemap (Optional[GameMap], optional) – Gamemap to place spawned entity in, defaults to None
- spawn(gamemap: GameMap, x: int, y: int) T¶
Spawn a copy of this instance at the given location at GameMap
- Parameters
self (T = TypeVar("T", bound="Entity")) – I don’t understand this part of the code
gamemap (GameMap) – Gamemap to spawn the entity in
x (int) – x coordinate of the entity
y (int) – y coordinate of the entity
- Returns
same as self : T = TypeVar(“T”, bound=”Entity”)
- Return type
T
- class entity.Item(*, x: int = 0, y: int = 0, char: str = '?', color: Tuple[int, int, int] = (255, 255, 255), name: str = '<Unnamed>', consumable: Optional[Consumable] = None, equippable: Optional[Equippable] = None)¶
Bases:
entity.EntityClass used to define items in our world Check entity_factories for some implementation examples
- parent: Union[GameMap, Inventory]¶