summaryrefslogtreecommitdiff
path: root/src/sliceitoff/text/explode.py
blob: aca14899be7b3c9939585696d4ffd7baa9914b33 (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
""" text.explode - Exploding effect movements and updates for the sprite """
from random import randrange

import pygame

from sliceitoff.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)