First steps
This commit is contained in:
parent
81190c687e
commit
1e731f5a80
191 changed files with 65 additions and 7 deletions
|
|
@ -5,6 +5,7 @@ from __future__ import annotations
|
|||
from typing import Final, Self
|
||||
|
||||
import attrs
|
||||
import math
|
||||
import tcod.ecs.callbacks
|
||||
from tcod.ecs import Entity
|
||||
|
||||
|
|
@ -18,9 +19,19 @@ class Position:
|
|||
|
||||
def __add__(self, direction: tuple[int, int]) -> 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]):
|
||||
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 length(self):
|
||||
return math.sqrt(self.x**2+self.y**2)
|
||||
|
||||
@tcod.ecs.callbacks.register_component_changed(component=Position)
|
||||
def on_position_changed(entity: Entity, old: Position | None, new: Position | None) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue