"""Viewport camera that eases toward the player each frame (plan.md Juice).""" from __future__ import annotations import math class Camera: """Pixel-space camera top-left. Eases toward its target; can snap.""" def __init__(self) -> None: self.x: float = 0.0 self.y: float = 0.0 self._tx: float = 0.0 self._ty: float = 0.0 def set_target(self, px: float, py: float) -> None: self._tx = px self._ty = py def snap(self, px: float, py: float) -> None: self.x = self._tx = px self.y = self._ty = py def update(self, dt: float, ease: float = 7.0) -> None: k = 1.0 - math.exp(-ease * dt) self.x += (self._tx - self.x) * k self.y += (self._ty - self.y) * k