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/initials.py | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'src/sliceitoff/game/initials.py') diff --git a/src/sliceitoff/game/initials.py b/src/sliceitoff/game/initials.py index 7811afa..9fb5a68 100644 --- a/src/sliceitoff/game/initials.py +++ b/src/sliceitoff/game/initials.py @@ -3,45 +3,30 @@ import pygame from screens import initials_screen -from .anykey import anykey +from .explodeout import ExplodeOutGroup -class Initials(pygame.sprite.Group): +class Initials(ExplodeOutGroup): """ Sprite group that asks initials to self.name from user """ def __init__(self): super().__init__() self.add(initials_screen("")) self.name = "" - self.explode = False - self.active = True - self.fadeout = 1_000 def update(self, dt = 0, **kwargs): """ Does it all. Reads keyboard and updates screen """ - if not self.active: - return - - super().update(dt = dt, explode = self.explode, **kwargs) - - if self.explode: - if self.fadeout <= 0: - self.active = False - else: - if anykey(): - self.fadeout = 0 - self.active = False - self.fadeout -= dt + if not super().update(dt = dt, **kwargs): return for event in pygame.event.get(): if event.type == pygame.QUIT: - self.explode = True + self.do_fadeout() break if event.type == pygame.KEYDOWN: if event.key in ( pygame.K_ESCAPE, pygame.K_KP_ENTER, pygame.K_RETURN): - self.explode = True + self.do_fadeout() break if event.key in ( pygame.K_RSHIFT, -- cgit v1.2.3