-
Notifications
You must be signed in to change notification settings - Fork 0
/
particles.py
63 lines (55 loc) · 1.42 KB
/
particles.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
59
60
61
62
63
import pygame
import random
import math
import globalconst
class Particle():
def __init__(self):
self.x=-1 # position; <0 means inactive
self.y=0 # position
self.xv=0 # velocity
self.yv=0 # velocity
self.c=(0,0,0) # color
PS_N=0
PS_I=0
psE=[]
def particlesInit():
global PS_N
global PS_I
global psE
PS_N=1024
PS_I=0
psE=[]
for i in range(PS_N):
psE.append(Particle())
def particlesCreate(x,y,xSpeed,ySpeed,rndSpeed,color,count):
global PS_N
global PS_I
global psE
for i in range(count):
PS_I+=1
if PS_I==PS_N:
PS_I=0
psE[PS_I].x=x
psE[PS_I].y=y
psE[PS_I].xv=xSpeed+random.uniform(-rndSpeed,rndSpeed)
psE[PS_I].yv=ySpeed+random.uniform(-rndSpeed,rndSpeed)
psE[PS_I].c=color
def particlesUpdate():
global psE
for e in psE:
e.x+=e.xv
e.y+=e.yv
e.yv+=0.02
e.xv*=0.99
e.yv*=0.99
def particlesRender(surface,camera):
global psE
for e in psE:
surface.set_at((round(e.x-camera[0]),round(e.y-camera[1])),e.c)
# screen crumble effect
if random.uniform(0,1)<0.1:
x=round(random.uniform(0,surface.get_size()[0]-1))
y=round(random.uniform(0,surface.get_size()[1]-1))
c=surface.get_at((x,y))
if c!=(0,0,0):
particlesCreate(x+camera[0],y+camera[1],0,0,0,c,1)