summaryrefslogtreecommitdiff
path: root/src/sliceitoff/player/life.py
diff options
context:
space:
mode:
authorViljami Ilola <+@hix.fi>2024-04-08 21:03:40 +0300
committerViljami Ilola <+@hix.fi>2024-04-08 21:03:40 +0300
commit9548295de1d343e831baaa2e1c908f70cef0e33a (patch)
treee9cb817de24b179beb842ec356e542ce22cde086 /src/sliceitoff/player/life.py
parentc99a7138e78352c4e26483dd4dad36b009a72e4f (diff)
life group. indicator for lost life
Diffstat (limited to 'src/sliceitoff/player/life.py')
-rw-r--r--src/sliceitoff/player/life.py40
1 files changed, 40 insertions, 0 deletions
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])))