From 6ba20c61a04c688120161f6c5fbb56102f8082ef Mon Sep 17 00:00:00 2001 From: Viljami Ilola <+@hix.fi> Date: Sun, 7 Apr 2024 23:25:09 +0300 Subject: exploding sprites and groups as their own. more refactoring. --- src/sliceitoff/game/show.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 'src/sliceitoff/game/show.py') diff --git a/src/sliceitoff/game/show.py b/src/sliceitoff/game/show.py index 0fb6e05..eaf3658 100644 --- a/src/sliceitoff/game/show.py +++ b/src/sliceitoff/game/show.py @@ -1,32 +1,23 @@ """ Sprite group that show sprites and skips if key is pressed """ -import pygame from .anykey import anykey +from .explodeout import ExplodeOutGroup -class Show(pygame.sprite.Group): +class Show(ExplodeOutGroup): """ To show some sprites and quit on any key """ def __init__(self, sprites = None, active = True): - super().__init__() + super().__init__(active = active) 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) + if not super().update(dt = dt, **kwargs): + return + if anykey(): + self.do_fadeout() + if self.timeout <= 0: + self.do_fadeout() + self.timeout -= dt def sprites(self): """ Return sprites only when active """ -- cgit v1.2.3