summaryrefslogtreecommitdiff
path: root/src/sliceitoff/game/show.py
blob: 0fb6e0591f094e08d6bce23836531eec2d2180c0 (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
""" Sprite group that show sprites and skips if key is pressed """
import pygame
from .anykey import anykey

class Show(pygame.sprite.Group):
    """ To show some sprites and quit on any key """
    def __init__(self, sprites = None, active = True):
        super().__init__()
        self.add(sprites)
        self.active = active
        self.explode = False
        self.fadeout = 1_000
        self.timeout = 15_000

    def update(self, dt = 0, **kwargs):
        """ First timeout then fadeout and then inactivity """
        if self.fadeout <= 0:
            self.active = False
        elif self.timeout <= 0:
            if anykey():
                self.fadeout = 0
            self.fadeout -= dt
            self.explode = True
        else:
            if anykey():
                self.timeout = 0
            self.timeout -= dt
        for sprite in self.sprites():
            sprite.update(dt = dt, explode = self.explode, **kwargs)

    def sprites(self):
        """ Return sprites only when active """
        return super().sprites() if self.active else []