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/text/explode.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/sliceitoff/text/explode.py (limited to 'src/sliceitoff/text/explode.py') diff --git a/src/sliceitoff/text/explode.py b/src/sliceitoff/text/explode.py new file mode 100644 index 0000000..4925398 --- /dev/null +++ b/src/sliceitoff/text/explode.py @@ -0,0 +1,27 @@ +""" text.explode - Exploding effect movements and updates for the sprite """ +from random import randrange + +import pygame + +from display import Scaling + +class ExplodingSprite(pygame.sprite.Sprite): + """ Just adds exloding movement to the sprite """ + def __init__(self): + super().__init__() + self.rect = None + self.direction = ( + Scaling.factor * (1_000 - randrange(2_000)), + Scaling.factor * (1_000 - randrange(2_000))) + + def update(self, dt = 0, explode = 0): + """ Exploding movement """ + if explode and dt: + self.rect = pygame.Rect( + self.rect.x + self.direction[0] * dt, + self.rect.y + self.direction[1] * dt, + self.rect.w, + self.rect.h) + self.direction = ( + self.direction[0] * 0.95, + self.direction[1] * 0.95 + 0.3) -- cgit v1.2.3