/
Vibek
/
First_Game
Обзор
Документация
Войти
/
Vibek
/
First_Game
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
resources/sprite_processor.py
40 строк
1 KB
Vibek
Спрайты и хитбоксы натянуты и синхронизированы
19 июн 2026, 13:56
19 июн 2026, 13:56
e17c6dd
Код
Авторство
О чём код?
"""Пост-обработка спрайтов при загрузке (Infrastructure).""" import pygame from resources.entity_profile import SpriteLayout class SpriteProcessor: """Single Responsibility: подготовка Surface из PNG к отрисовке.""" @classmethod def prepare(cls, surface: pygame.Surface, layout: SpriteLayout) -> pygame.Surface: if layout.colorkey is not None: surface = cls._apply_colorkey(surface, layout.colorkey, layout.colorkey_tolerance) if pygame.display.get_surface() is not None: return surface.convert_alpha() return surface.convert_alpha() if surface.get_flags() & pygame.SRCALPHA else surface @staticmethod def _apply_colorkey( surface: pygame.Surface, color: tuple[int, int, int], tolerance: int, ) -> pygame.Surface: result = surface.convert_alpha() width, height = result.get_size() target_r, target_g, target_b = color for y in range(height): for x in range(width): red, green, blue, alpha = result.get_at((x, y)) if alpha == 0: continue if ( abs(red - target_r) <= tolerance and abs(green - target_g) <= tolerance and abs(blue - target_b) <= tolerance ): result.set_at((x, y), (0, 0, 0, 0)) return result