""" player.life - Hearth that will explode """ import os import pygame from display import Scaling, CGA_COLORS from text import get_letter_surface, ExplodingSprite class PieceOfHearth(ExplodingSprite): def __init__(self, image, pos): super().__init__() self.image = image self.rect = self.image.get_rect().move(pos) class Life(pygame.sprite.Group): """ The slicer. Special sprite group that only list 1 sprite """ def __init__(self): super().__init__() self.timeout = 0 def update(self, loselife = False, dt = 0, **kwargs): explode = True if self.timeout < 1_000 else False super().update(dt = dt, explode = explode, **kwargs) if self.timeout > 0: self.timeout -= dt else: self.empty() def lose_life(self): self.timeout = 2_000 font_width = int(Scaling.factor * 200_000) block_width = int(Scaling.factor * 8_000) offset = ( int(Scaling.factor * 72_500 + Scaling.left), int(Scaling.factor * 20_000 + Scaling.top)) srfc = get_letter_surface(("8x8", 200_000, 4), 0x03) for x in range(0, font_width, block_width): for y in range(0, font_width, block_width): image = srfc.subsurface((x, y, block_width, block_width)) self.add(PieceOfHearth(image,(x + offset[0], y + offset[1])))