-
Notifications
You must be signed in to change notification settings - Fork 0
/
particle_system.py
58 lines (36 loc) · 1.73 KB
/
particle_system.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#init stuff
import pygame
import random
from particle import Particle
pygame.init()
#makes a new class
class Particle_System:
#this method is always called when a new instance of a class is created
def __init__(self, particle_amount, img, x, y, vector_min, vector_max, speed_min, speed_max, lifetime_min, lifetime_max):
#creating all the values the particle needs
self.particle_amount = particle_amount
self.img = img
self.x = x
self.y = y
self.vector_constraints = [vector_min, vector_max]
self.speed_constraints = [speed_min, speed_max]
self.lifetime_constraints = [lifetime_min, lifetime_max]
self.particles = []
#draw method, must be placed after background is drawn but before display is updated
def draw(self, screen, camera):
#iterates through each particle in the system
for particle in self.particles:
particle.draw(screen, camera)
#update method, moves the particles, and creates and removes them as needed
def update(self):
for particle in self.particles:
if particle.dead == True:
self.particles.remove(particle)
if len(self.particles) < self.particle_amount:
new_particle = Particle(self.img, self.x, self.y,
random.randint(self.vector_constraints[0], self.vector_constraints[1]),
random.randint(self.speed_constraints[0], self.speed_constraints[1]),
random.randint(self.lifetime_constraints[0], self.lifetime_constraints[1]))
self.particles.append(new_particle)
for particle in self.particles:
particle.update()