(Underdepths) Pass 2
This commit is contained in:
1 parent
4a5a92cb74
commit
b49c285c89
37 files changed
+5590
No files matched your search
@@ -0,0 +1,35 @@
|
||||
"""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
|
||||
Reference in new issue
Block a user