2022-04-26 22:25:04 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Eryn Wells <eryn@erynwells.me>
|
|
|
|
|
|
|
|
import tcod
|
2022-05-01 09:29:30 -07:00
|
|
|
from .geometry import Point
|
|
|
|
from typing import Optional
|
2022-04-26 22:25:04 -07:00
|
|
|
|
2022-05-01 09:29:30 -07:00
|
|
|
class Entity:
|
|
|
|
'''A single-tile drawable entity with a symbol and position.'''
|
2022-04-26 22:25:04 -07:00
|
|
|
|
2022-05-01 09:51:22 -07:00
|
|
|
def __init__(self, symbol: str, *,
|
|
|
|
position: Optional[Point] = None,
|
|
|
|
fg: Optional[tcod.Color] = None,
|
|
|
|
bg: Optional[tcod.Color] = None):
|
2022-05-01 09:29:30 -07:00
|
|
|
self.position = position if position else Point()
|
2022-05-01 09:51:22 -07:00
|
|
|
self.foreground = fg if fg else tcod.white
|
|
|
|
self.background = bg
|
2022-05-01 09:29:30 -07:00
|
|
|
self.symbol = symbol
|
2022-04-27 13:53:42 -07:00
|
|
|
|
2022-04-30 23:30:23 -07:00
|
|
|
def print_to_console(self, console: tcod.Console) -> None:
|
2022-05-01 09:51:22 -07:00
|
|
|
console.print(x=self.position.x, y=self.position.y, string=self.symbol, fg=self.foreground, bg=self.background)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f'{self.symbol}[{self.position}]'
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return f'{self.__class__.__name__}({self.symbol}, position={self.position}, fg={self.foreground}, bg={self.background})'
|