"""Base entities: geometric Rect and the generic Entity.""" from dataclasses import dataclass @dataclass(slots=True) class Rect: x: int y: int w: int h: int @property def center(self) -> tuple[int, int]: return (self.x + self.w // 2, self.y + self.h // 2) def intersects(self, other: "Rect") -> bool: # True when the two rectangles' interiors overlap (strict inequalities). return ( self.x < other.x + other.w and self.x + self.w > other.x and self.y < other.y + other.h and self.y + self.h > other.y ) @dataclass(slots=True) class Entity: x: int y: int name: str glyph: str color: tuple blocks: bool = True is_alive: bool = True