diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-18 16:27:51 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-18 16:27:51 +0200 |
commit | 89bf2bf2197e44f0745bcae1400227c2999573cd (patch) | |
tree | b8c75505a2f860c32b01802dc037fdae2b3f73c5 /src/sliceitoff/status | |
parent | 78c665af8b860063658d1782f75e072cfe88c82b (diff) |
fonts from fnt-file
Diffstat (limited to 'src/sliceitoff/status')
-rw-r--r-- | src/sliceitoff/status/status.py | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/sliceitoff/status/status.py b/src/sliceitoff/status/status.py index d99c7d5..a63a7db 100644 --- a/src/sliceitoff/status/status.py +++ b/src/sliceitoff/status/status.py @@ -2,20 +2,31 @@ import os import pygame from display import Scaling -from images import Images +from images import Images, Fonts class LetterSprite(pygame.sprite.Sprite): def __init__(self, image, pos): super().__init__() self.image = image self.rect = self.image.get_rect().move(pos) - + +class TextGroup(pygame.sprite.Group): + def __init__(self, text, pos, size = 8_000, spacing = None, font = 'lcd'): + super().__init__() + if spacing == None: + spacing = size + for i in range(len(text)): + image = pygame.transform.scale_by( + Fonts.fonts[font].get(text[i]), + size/8 * Scaling.factor) + image_pos = Scaling.scale_to_display( (pos[0]+i*spacing, pos[1]) ) + self.add(LetterSprite(image, image_pos)) class Status(): def __init__(self, level = 1): self.score = 0 self.bonus = 20_000 - self.health = 3 + self.lives = 3 self.level = level self.sprites = pygame.sprite.Group() @@ -24,12 +35,17 @@ class Status(): self.bonus = max(0, self.bonus - dt) - self.sprites.empty() - y = 280_000 - #score_str="{:010d}".format(self.score) - score_str="{:010d}".format(self.bonus) - for letter, x in zip(score_str, range(300_000,400_000,10_000)): - self.sprites.add(LetterSprite( - Images.surfaces[f"letter_{letter}"], - Scaling.scale_to_display((x,y)) )) - self.updated = False + score_str="LEVEL{:02d}LIVES{:02d}{:010d}".format(self.level, self.lives, self.bonus) + self.sprites = TextGroup( + score_str, + (0, 280_000), + size = 10_000) + + def lose_life(self): + """ Lose 1 life and return true if no lives left """ + self.lives -= 1 + return not self.lives + + def gain_life(self): + """ Gain 1 life """ + self.lives += 1 |