summaryrefslogtreecommitdiffstats
path: root/Geometry-Dash/particle.py
blob: 690405e624199d19b78a654a042d09c93d45e7f7 (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
34
35
36
37
38
39
40
41
42
import pygame.draw
from setup import *
from colors import *
from math import sin


class Particles:

    def __init__(self):
        self.particles = []

    def add_particles(self, particle_type, time):
        self.particles.append(str(particle_type) + str(time))

    def update(self, delta_time):
        new_particles = []
        for num, particle in enumerate(self.particles):
            particle_type = particle[0]
            time = float(particle[1::])
            if max(time, 1) == 1:
                del self.particles[num]
            else:
                if particle_type == 'c':
                    time -= delta_time
                elif particle_type == 'r':
                    time -= random.randint(delta_time, 2 * delta_time)
                new_particles.append(str(particle_type) + str(time))
        self.particles = new_particles

    def draw(self, screen, x, y):
        for num, particle in enumerate(self.particles):
            particle_type = particle[0]
            time = float(particle[1::])
            if particle_type == 'c':
                pygame.draw.circle(screen, COLOR_ORANGE, (x, y), 0.02 * (1501 - time), 0)
            elif particle_type == 'r':
                i = random.randint(-1, 1)
                if i == -1:
                    r = pygame.Rect(x + 40 * sin(time), y + 40 * sin(time), 5, 5)
                else:
                    r = pygame.Rect(x - 40 * sin(time), y + 40 * sin(time), 5, 5)
                pygame.draw.rect(screen, COLOR_BLACK, r)