2022-04-26 22:25:04 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Eryn Wells <eryn@erynwells.me>
|
|
|
|
|
|
|
|
import tcod
|
2022-04-30 21:59:33 -07:00
|
|
|
from .geometry import Point, Vector
|
2022-04-26 22:25:04 -07:00
|
|
|
|
|
|
|
class Object:
|
2022-04-27 13:53:42 -07:00
|
|
|
'''A drawable object with a symbol and (x, y) position.'''
|
2022-04-26 22:25:04 -07:00
|
|
|
|
2022-04-27 13:53:42 -07:00
|
|
|
def __init__(self, symbol: str, color: tcod.Color = (255, 255, 255), x: int = 0, y: int = 0):
|
2022-04-26 22:25:04 -07:00
|
|
|
self.__x = int(x)
|
|
|
|
self.__y = int(y)
|
2022-04-27 08:19:56 -07:00
|
|
|
self.__color = color
|
|
|
|
self.__symbol = symbol
|
2022-04-26 22:25:04 -07:00
|
|
|
|
|
|
|
@property
|
|
|
|
def x(self):
|
|
|
|
return self.__x
|
|
|
|
|
|
|
|
@x.setter
|
|
|
|
def x(self, value):
|
|
|
|
self.__x = int(value)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def y(self):
|
|
|
|
return self.__y
|
|
|
|
|
|
|
|
@y.setter
|
|
|
|
def y(self, value):
|
|
|
|
self.__y = int(value)
|
|
|
|
|
2022-04-30 21:59:33 -07:00
|
|
|
def move(self, delta: Vector):
|
2022-04-27 13:53:42 -07:00
|
|
|
'''Move this object by (dx, dy).'''
|
2022-04-30 21:59:33 -07:00
|
|
|
self.__x += delta.dx
|
|
|
|
self.__y += delta.dy
|
2022-04-27 13:53:42 -07:00
|
|
|
|
2022-04-30 21:59:33 -07:00
|
|
|
def move_to(self, point: Point) -> None:
|
2022-04-27 13:53:42 -07:00
|
|
|
'''Move this object directly to the given position.'''
|
2022-04-30 21:59:33 -07:00
|
|
|
self.__x = point.x
|
|
|
|
self.__y = point.y
|
2022-04-27 13:53:42 -07:00
|
|
|
|
2022-04-26 22:25:04 -07:00
|
|
|
def print(self, console: tcod.Console) -> None:
|
2022-04-27 08:19:56 -07:00
|
|
|
console.print(x=self.__x, y=self.__y, string=self.__symbol, fg=self.__color)
|