From 95afab543105951227511c796f89da756c4e9faf Mon Sep 17 00:00:00 2001 From: Brosef Date: Sat, 21 Jun 2025 23:03:38 +0100 Subject: [PATCH] Implemented centre() --- src/gameUtils/utils.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/gameUtils/utils.py b/src/gameUtils/utils.py index ae75447..2cb4b65 100644 --- a/src/gameUtils/utils.py +++ b/src/gameUtils/utils.py @@ -1,14 +1,22 @@ import pygame -def centre(surface: pygame.Surface, rect: tuple[int, int, int, int]) -> pygame.Surface: +def centre(surface: pygame.Surface, size: tuple[int, int]) -> pygame.Surface: """ Centres a surface within a given rectangle. Args: surface: The surface to be centred. - rect: The rectangle the surface will be centred in. + size: The size of the rectangle the surface will be centred in. Returns: pygame.Surface """ - pass \ No newline at end of file + + surf = pygame.Surface(size) + offX = surf.size[0]//2 - surface.size[0]//2 + offY = surf.size[1]//2 - surface.size[1]//2 + + surf.blit(surface, (offX, offY)) + + return surf + \ No newline at end of file