From 6c43e3b3ab77ec0c3c57763178723a50e4dcac52 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Wed, 19 Apr 2023 02:09:53 +0200 Subject: Added the ghost sprites to the game. --- src/util.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/util.py (limited to 'src/util.py') diff --git a/src/util.py b/src/util.py new file mode 100644 index 0000000..66fecb4 --- /dev/null +++ b/src/util.py @@ -0,0 +1,28 @@ +from typing import List +import pygame + + +def get_sprites(sprite_sheet) -> List: + sheet_width, sheet_height = sprite_sheet.get_size() + sprite_width, sprite_height = 32, 32 + rows = sheet_height // sprite_height + columns = sheet_width // sprite_width + sprites = [] + + for row in range(rows): + for col in range(columns): + x = col * sprite_width + y = row * sprite_height + + # Create a new surface for the current sprite and blit it from the + # sprite sheet onto this new surface + new_sprite_surface = pygame.Surface( + (sprite_width, sprite_height), pygame.SRCALPHA) + new_sprite_surface.blit( + sprite_sheet, (0, 0), (x, y, x + sprite_width, y + sprite_height)) + + # Add this new surface to our list of sprites + sprites.append(new_sprite_surface) + + return sprites + -- cgit v1.2.3