center player and stuff

This commit is contained in:
staubsauger 2024-08-16 22:25:11 +02:00
parent 6cd571476f
commit 36d6b63c31
4 changed files with 21 additions and 5 deletions

View file

@ -17,19 +17,27 @@ class Position:
x: int
y: int
def __add__(self, direction: tuple[int, int]) -> Self:
def __add__(self, direction: tuple[int, int] | Position) -> Self:
"""Add a vector to this position."""
match direction:
case Position(x, y):
return self.__class__(self.x + x, self.y + y)
x, y = direction
return self.__class__(self.x + x, self.y + y)
def __sub__(self, direction: tuple[int, int]):
def __sub__(self, direction: tuple[int, int] | Position) -> Self:
match direction:
case Position(x, y):
return self.__class__(self.x - x, self.y - y)
x, y = direction
return self.__class__(self.x - x, self.y - y)
def mod(self, other: tuple[int,int] | Position | int) -> Self:
match other:
case Position(x,y):
return self.__class__(self.x//x, self.y//y)
case int(x):
return self.__class__(self.x//x, self.y//x)
x,y = other
return self.__class__(self.x//x, self.y//y)
def length(self):
return math.sqrt(self.x**2+self.y**2)