diff options
Diffstat (limited to 'src/sliceitoff/player')
-rw-r--r-- | src/sliceitoff/player/__init__.py | 1 | ||||
-rw-r--r-- | src/sliceitoff/player/life.py | 40 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/sliceitoff/player/__init__.py b/src/sliceitoff/player/__init__.py index 12ca32c..16d890e 100644 --- a/src/sliceitoff/player/__init__.py +++ b/src/sliceitoff/player/__init__.py @@ -1,2 +1,3 @@ """ player - The slicing tool on the screen """ from .player import Player +from .life import Life diff --git a/src/sliceitoff/player/life.py b/src/sliceitoff/player/life.py new file mode 100644 index 0000000..7d72729 --- /dev/null +++ b/src/sliceitoff/player/life.py @@ -0,0 +1,40 @@ +""" 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]))) |