summaryrefslogtreecommitdiff
path: root/src/sliceitoff/status/status.py
blob: f6517da58f9cbe7e05237f6029d4e95e8d2e2c3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import pygame

from display import Scaling
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.lives = 3
        self.level = level
        self.sprites = pygame.sprite.Group()
        
    def update(self, dt):
        """ Update sprites basis of dt. dt = milliseconds from last update """

        self.bonus = max(0, self.bonus - dt)
        
        score_str = (
                "{:02d}\x12 {:02d}\xfe {:02d}\x03 "
                "{:02d}\x0e {:08d}\x0f").format(
                    self.level,
                    99 if 100 == 100 else 99,
                    self.lives,
                    self.bonus // 1000,
                    self.score)
        self.sprites = TextGroup(
                score_str,
                (0, 282_000),
                size = 16_000,
                font = '8x8')

    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