Create a Hero class for the character the player moves; stop using tcod.Color for foreground and background; use tuples instead

This commit is contained in:
Eryn Wells 2022-05-06 21:16:00 -07:00
parent 5f6247ef13
commit 1e69667ba8

View file

@ -3,17 +3,17 @@
import tcod
from .geometry import Point
from typing import Optional
from typing import Optional, Tuple
class Entity:
'''A single-tile drawable entity with a symbol and position.'''
def __init__(self, symbol: str, *,
position: Optional[Point] = None,
fg: Optional[tcod.Color] = None,
bg: Optional[tcod.Color] = None):
fg: Optional[Tuple[int, int, int]] = None,
bg: Optional[Tuple[int, int, int]] = None):
self.position = position if position else Point()
self.foreground = fg if fg else tcod.white
self.foreground = fg if fg else (255, 255, 255)
self.background = bg
self.symbol = symbol
@ -24,4 +24,8 @@ class Entity:
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})'
return f'{self.__class__.__name__}({self.symbol}, position={self.position}, fg={self.foreground}, bg={self.background})'
class Hero(Entity):
def __init__(self, position: Point):
super().__init__('@', position=position, fg=tuple(tcod.white))