Skip to content

Commit

Permalink
Setting relative distance on sprite now properly updates distance.
Browse files Browse the repository at this point in the history
  • Loading branch information
salt-die committed Mar 28, 2024
1 parent 1627003 commit 4b81e5c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/terminal_dungeon/read_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,21 @@ class Sprite:

def __post_init__(self) -> None:
self.pos = np.asarray(self.pos)
self._relative: NDArray[np.float64] = np.zeros(2)
self._relative: NDArray[np.float32] = np.zeros(2)
"""Relative distance from camera."""
self.distance: np.float64 = 0.0
self.distance: np.float32 = 0.0
"""Distance from camera."""

@property
def relative(self) -> NDArray[np.float32]:
"""Relative distance from camera."""
return self._relative

@relative.setter
def relative(self, relative: NDArray[np.float32]):
self._relative = relative
self.distance = relative @ relative

def __lt__(self, other) -> bool:
"""Sprites are ordered by their distance to camera."""
return self.distance > other.distance
Expand Down

0 comments on commit 4b81e5c

Please # to comment.