-
Notifications
You must be signed in to change notification settings - Fork 0
/
particle.py
44 lines (32 loc) · 1.05 KB
/
particle.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
from pygame import draw, Vector2
class Particle:
particles = []
visible = True
draw_radius = 4
def __init__(self, pos: Vector2):
self.pos = pos
self.vel = Vector2(0,0)
self.forces = Vector2(0,0)
Particle.particles.append(self)
@staticmethod
def updateAll(dT):
for particle in Particle.particles:
particle.update(dT)
@staticmethod
def renderAll(screen):
if Particle.visible:
for particle in Particle.particles:
particle.render(screen)
def update(self, dT):
self.vel += self.forces * dT
self.pos += self.vel * dT
self.forces *= 0
def render(self, screen):
draw.circle(screen, (255, 0, 0), self.pos, self.draw_radius)
def applyForce(self, force: Vector2):
self.forces += force
@staticmethod
def deleteAll():
Particle.particles = []
def delete(self):
Particle.particles.remove(self)