Skip to content

Commit 7e93964

Browse files
committed
Migrate Entity to FRect
1 parent f5bc538 commit 7e93964

5 files changed

Lines changed: 11 additions & 11 deletions

File tree

docs/scripting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ The `engine.core.Entity` class has the following properties:
7878
| `width` | Width in pixels | `float` |
7979
| `height` | Height in pixels | `float` |
8080
| `color` | RGB color value | `tuple[int, int, int]` |
81-
| `rect` | Pygame rect object on screen | `pygame.Rect` |
81+
| `rect` | Pygame rect object on screen | `pygame.FRect` |
8282
| `scriptfile` | Path to the attached script | `str` |
8383
| `image` | Image attached to entity | `EntityImage` or `None` |
8484
| `id` | Unique entity UUID | `str` |

engine/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(
7474
int(clamp(color[2], 0, 255)),
7575
)
7676

77-
self.rect: pygame.Rect = pygame.Rect(self.x, self.y, self.width, self.height)
77+
self.rect: pygame.FRect = pygame.FRect(self.x, self.y, self.width, self.height)
7878
self.id: str = str(uuid.uuid4())
7979

8080
self.parent: Optional["Scene"] = None

engine/core/animation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import bisect
99
import pygame
1010

11-
from typing import Optional
11+
from typing import Optional, Union
1212

1313

1414
class EntityAnim:
@@ -48,7 +48,7 @@ def __init__(self, anim_path: str, loop: bool = True) -> None:
4848
self._started_at: int = 0
4949

5050
self._scaled: Optional[pygame.Surface] = None
51-
self._scaled_key: Optional[tuple[int, int, int]] = None
51+
self._scaled_key: Optional[tuple[int, float, float]] = None
5252

5353
self.set_image(anim_path)
5454

@@ -139,19 +139,19 @@ def _current_index(self) -> int:
139139

140140
return bisect.bisect_right(self._starts, elapsed) - 1
141141

142-
def draw(self, surface: pygame.Surface, rect: pygame.Rect) -> None:
142+
def draw(self, surface: pygame.Surface, rect: Union[pygame.Rect, pygame.FRect]) -> None:
143143
"""
144144
Draw the current frame of the animation scaled to ``rect`` onto ``surface``.
145145
146146
Args:
147147
surface (pygame.Surface): surface to draw onto
148-
rect (pygame.Rect): rect to scale image to
148+
rect (pygame.Rect | pygame.FRect): rect to scale image to
149149
"""
150150

151151
assert self.frames, "EntityAnim.frames was not initialized" # nosec B101
152152

153153
index: int = self._current_index()
154-
key: tuple[int, int, int] = (index, rect.width, rect.height)
154+
key: tuple[int, float, float] = (index, rect.width, rect.height)
155155

156156
if key != self._scaled_key or self._scaled is None:
157157
self._scaled = pygame.transform.scale(self.frames[index], (rect.width, rect.height))

engine/core/image.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import pygame
99

10-
from typing import Optional
10+
from typing import Optional, Union
1111

1212

1313
class EntityImage:
@@ -44,13 +44,13 @@ def set_image(self, image_path: str) -> None:
4444

4545
self.surface = pygame.image.load(image_path).convert_alpha()
4646

47-
def draw(self, surface: pygame.Surface, rect: pygame.Rect) -> None:
47+
def draw(self, surface: pygame.Surface, rect: Union[pygame.Rect, pygame.FRect]) -> None:
4848
"""
4949
Draw the image scaled to ``rect`` onto ``surface``.
5050
5151
Args:
5252
surface (pygame.Surface): surface to draw onto
53-
rect (pygame.Rect): rect to scale image to
53+
rect (pygame.Rect | pygame.FRect): rect to scale image to
5454
"""
5555

5656
assert self.surface is not None, "EntityImage.surface was not initialized" # nosec B101

engine/core/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _update_text_surface(self) -> None:
7575
"""
7676

7777
self.text_surface = self.font.render(self.text, self.antialias, self.color, self.bgcolor)
78-
self.text_rect = self.text_surface.get_rect(x=self.x, y=self.y)
78+
self.text_rect = self.text_surface.get_frect(x=self.x, y=self.y)
7979

8080
def center(self, pos: tuple[float, float]) -> None:
8181
"""

0 commit comments

Comments
 (0)