Add some basic geometry primitives

Point, Vector, Size, and Rect. These are modeled on the CoreGraphics types.
This commit is contained in:
Eryn Wells 2022-04-30 21:59:33 -07:00
parent 9ddeef2561
commit 4f6d04456c
2 changed files with 72 additions and 6 deletions

View file

@ -2,6 +2,7 @@
# Eryn Wells <eryn@erynwells.me>
import tcod
from .geometry import Point, Vector
class Object:
'''A drawable object with a symbol and (x, y) position.'''
@ -28,15 +29,15 @@ class Object:
def y(self, value):
self.__y = int(value)
def move(self, dx: int, dy: int):
def move(self, delta: Vector):
'''Move this object by (dx, dy).'''
self.__x += dx
self.__y += dy
self.__x += delta.dx
self.__y += delta.dy
def move_to(self, x: int, y: int) -> None:
def move_to(self, point: Point) -> None:
'''Move this object directly to the given position.'''
self.__x = x
self.__y = y
self.__x = point.x
self.__y = point.y
def print(self, console: tcod.Console) -> None:
console.print(x=self.__x, y=self.__y, string=self.__symbol, fg=self.__color)